fix: getNextMatch() returns past dates near DST boundaries#508
Open
GabeK0 wants to merge 3 commits into
Open
Conversation
Replace lossy toLocaleString roundtrip in getTimezoneGMT() with Intl.DateTimeFormat shortOffset parsing. Add DST drift compensation in set() to preserve intended local time across boundary crossings.
GabeK0
commented
Mar 8, 2026
| import BackgroundScheduledTask from "./background-scheduled-task"; | ||
|
|
||
| import { EventEmitter } from 'stream'; | ||
| import { EventEmitter } from 'events'; |
Author
There was a problem hiding this comment.
'stream' does not export EventEmitter as a named ESM export; use 'events' instead. Fixes some broken tests
90164a9 to
f989527
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
getNextMatch()/getNextRun()can return timestamps in the past near DST transitions, causing infinite "missed execution" warnings in the scheduler.Two bugs in
localized-time.ts:getTimezoneGMT()derives offsets vianew Date(date.toLocaleString(...))roundtrip — the re-parsed string picks up the host timezone's offset at that wall-clock time, not the target timezone's. Replaced withIntl.DateTimeFormat('en-US', { timeZone, timeZoneName: 'shortOffset' })to parse the offset directly.set()doesn't account for DST boundary crossings. When setting a field moves the date across a DST transition, the offset changes and local time drifts by the offset delta. Added drift detection and timestamp correction after rebuilding parts.Reproduction
Verified across
America/New_York,America/Los_Angeles,America/Phoenix, andUTC.Test plan
* * * * *in DST-observing host TZ returns future timestamp*/5 * * * *in DST-observing host TZ returns future timestamp0 7 * * *with{ timezone: 'America/New_York' }returns next day (~8.5 hours), not Jan 2027npm run build)