Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timezone support #8

Open
P4sca1 opened this issue Oct 6, 2020 · 2 comments
Open

Add timezone support #8

P4sca1 opened this issue Oct 6, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@P4sca1
Copy link
Owner

P4sca1 commented Oct 6, 2020

At the moment, the cron jobs are checked against the local time.
When constructing a Schedule an optional timezone parameter could be used.
parseCronExpression would then get a second parameter timezone which is passed to the Schedule constructor.
For ease of use, it would be great if time zone names would be supported, but we would need to include and maintain a database of timezones. Also time zone offsets are not static but change over time and throughout the year. Maybe the timezone parameter should be a function utcOffset that returns the desired utc offset. One could then use other libraries such as moment-timezone to get the desired offset and cron-schedule bundle size would not increased (or use a peer dependency?). We also need to consider what happens when utcOffset returns diifferent offsets in subsequent calls (which might be realistic due to summer time / DST).

@P4sca1 P4sca1 added the enhancement New feature or request label Oct 6, 2020
@williamoverton
Copy link

For people finding this, we ended up switching to this library which has the same functionality plus timezone support: https://www.npmjs.com/package/cron-parser

@P4sca1
Copy link
Owner Author

P4sca1 commented Sep 16, 2024

Info on DST handling in cron:

Daylight Saving Time and other time changes
Local time changes of less than three hours, such as those caused
by the Daylight Saving Time changes, are handled in a special
way. This only applies to jobs that run at a specific time and
jobs that run with a granularity greater than one hour. Jobs
that run more frequently are scheduled normally.

If time was adjusted one hour forward, those jobs that would have
run in the interval that has been skipped will be run
immediately. Conversely, if time was adjusted backward, running
the same job twice is avoided.

Time changes of more than 3 hours are considered to be
corrections to the clock or the timezone, and the new time is
used immediately.

It is possible to use different time zones for crontables. See
crontab(5) for more information.

https://www.man7.org/linux/man-pages/man8/cron.8.html

For handling time zones, we can checkout the following library. Ideally it would be an optional peer dependency or not be part of the main entrypoint to keep bundle size low.
https://github.com/date-fns/tz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants