Repository navigation
cron: interpret Bun.cron.parse() and in-process schedules in local time; add { tz } option #35122
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9318a02
cron: interpret Bun.cron.parse() and in-process schedules in local time
robobun 7c534d7
[autofix.ci] apply automated fixes
autofix-ci[bot] 189feca
review: dedupe test suites, share JSGlobalObject date helpers, drop F…
robobun a464488
[autofix.ci] apply automated fixes
autofix-ci[bot] 18b1b18
review: drop now-dead ms_to_gregorian_date_time_utc; pipe stderr in t…
robobun 1a19e7c
cron: add { tz } option; pin cron.test.ts parse block to UTC
robobun 35fef5a
[autofix.ci] apply automated fixes
autofix-ci[bot] bb7f663
cron: suppress Temporal UCalendar LRU under LSan; add CronOptions typ…
robobun b2ac074
review: reject empty/non-ASCII tz; gate fall-back probe on actual ove…
robobun 3ccd95e
test: restore Feb-30 perf assertion in-process via { tz: 'UTC' }
robobun 8520c37
cron: probe forward when ambiguous dt maps before from_ms; fix TZ res…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7606,6 +7606,17 @@ | |
| unref(): CronJob; | ||
| } | ||
|
|
||
| /** | ||
| * Options for the in-process {@link Bun.cron} callback overload and {@link Bun.cron.parse}. | ||
| */ | ||
| interface CronOptions { | ||
| /** | ||
| * IANA time-zone name to interpret the schedule in (e.g. `"UTC"`, | ||
| * `"America/New_York"`). Defaults to the system's local time zone. | ||
| */ | ||
| tz?: string; | ||
| } | ||
|
Check warning on line 7618 in packages/bun-types/bun.d.ts
|
||
|
|
||
| /** | ||
| * Schedule cron jobs. | ||
| * | ||
|
|
@@ -7647,8 +7658,7 @@ | |
| * | ||
| * ### Cron expression syntax | ||
| * | ||
| * Five fields: `minute hour day-of-month month day-of-week`. Schedules are | ||
| * interpreted in **UTC** — `0 9 * * *` fires at 9:00 UTC, regardless of `TZ`. | ||
| * Five fields: `minute hour day-of-month month day-of-week`. | ||
| * | ||
| * | Field | Values | Special chars | | ||
| * |-------|--------|---------------| | ||
|
|
@@ -7702,7 +7712,7 @@ | |
| * @see {@link CronJob} for the returned handle. | ||
| * @see {@link Bun.cron.parse} to preview the next fire time. | ||
| */ | ||
| (schedule: CronWithAutocomplete, handler: (this: CronJob) => unknown): CronJob; | ||
| (schedule: CronWithAutocomplete, handler: (this: CronJob) => unknown, options?: CronOptions): CronJob; | ||
| /** | ||
| * Register an **OS-level** cron job that runs a JavaScript/TypeScript module on a schedule. | ||
| * | ||
|
|
@@ -7802,7 +7812,10 @@ | |
| */ | ||
| remove(title: string): Promise<void>; | ||
| /** | ||
| * Parse a cron expression and return the next matching `Date` in UTC. | ||
| * Parse a cron expression and return the next matching `Date` in the | ||
| * system's local time zone — the same way crontab, launchd, and Windows | ||
| * Task Scheduler interpret schedules. Pass `{ tz: "UTC" }` (or any IANA | ||
| * time-zone name) to override. | ||
| * | ||
| * Supports the same syntax as {@link Bun.cron} — 5-field expressions, named | ||
| * days/months, and predefined nicknames like `@daily`. | ||
|
|
@@ -7811,23 +7824,31 @@ | |
| * matching uses OR logic per [POSIX cron](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html): | ||
| * a date matches if **either** field matches. | ||
| * | ||
| * DST: spring-forward times shift forward by the gap; in the fall-back | ||
| * duplicated hour, fixed-time schedules fire once (first occurrence) while | ||
| * schedules with `*` minute or hour fire through both occurrences. | ||
| * | ||
| * @param expression - A cron expression or nickname (e.g. `"0,15,30,45 * * * *"`, `"0 9 * * MON-FRI"`, `"@hourly"`) | ||
| * @param relativeDate - Starting point for the search (defaults to `Date.now()`). Accepts a `Date` or milliseconds since epoch. | ||
| * @returns The next `Date` matching the expression in UTC, or `null` if no match exists within 8 years (e.g. `"0 0 30 2 *"` — Feb 30 never occurs) | ||
| * @throws If the expression is invalid or `relativeDate` is `NaN`/`Infinity` | ||
| * @param options - `{ tz?: string }` — IANA time-zone name to interpret the schedule in (defaults to the system's local zone). | ||
| * @returns The next `Date` matching the expression, or `null` if no match exists within 8 years (e.g. `"0 0 30 2 *"` — Feb 30 never occurs) | ||
| * @throws If the expression is invalid, `relativeDate` is `NaN`/`Infinity`, or `options.tz` is not a valid IANA name | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // Next weekday at 09:30 UTC | ||
| * // Next weekday at 09:30 local time | ||
| * const next = Bun.cron.parse("30 9 * * MON-FRI"); | ||
| * | ||
| * // 09:00 in New York, regardless of the server's TZ | ||
| * const ny = Bun.cron.parse("0 9 * * *", Date.now(), { tz: "America/New_York" }); | ||
| * | ||
| * // Chain calls to get a sequence | ||
| * const from = new Date(); | ||
| * const first = Bun.cron.parse("@hourly", from); | ||
| * const second = first ? Bun.cron.parse("@hourly", first) : null; | ||
| * ``` | ||
| */ | ||
| parse(expression: CronWithAutocomplete, relativeDate?: Date | number): Date | null; | ||
| parse(expression: CronWithAutocomplete, relativeDate?: Date | number, options?: CronOptions): Date | null; | ||
| }; | ||
|
|
||
| /** Utility type for any process from {@link Bun.spawn()} with both stdout and stderr set to `"pipe"` */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.