fix: do not return a date before start during a backward DST jump - #1088
Open
ChangkeunJ wants to merge 1 commit into
Open
fix: do not return a date before start during a backward DST jump#1088ChangkeunJ wants to merge 1 commit into
ChangkeunJ wants to merge 1 commit into
Conversation
When the clock is still before a fall-back transition, luxon resolves an ambiguous wall time to its first occurrence, so getNextDateFrom could hand back the earlier of the two identical hours even when start already sat in the later one. Take the later occurrence in that case. fixes kelektiv#1087
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.
Description
getNextDateFromrebuilds the matched wall time withDateTime.fromFormat(..., { zone }). In the repeated hour of a fall-back transition that wall time is ambiguous and luxon seeds it with the offset of the current clock (fromObject,zone.offset(Settings.now())), so before the transition it picks the first occurrence. Whenstartalready sits in the second occurrence the result comes back 30 to 60 minutes beforestart, and the two follow-up checks in that function only ever move the result earlier, so nothing catches it.This adds one guard after those checks: if the resolved date is not after
start, try +30, +60 and +120 minutes and return the one that keeps the same hour and minute and is afterstart. Those three steps cover every backward offset change in tzdata for 2026 and 2027.Related Issue
fixes #1087
Motivation and Context
getNextDateFrom(date, tz),CronJob.nextDates(n)andCronTime.sendAt(n)return a date in the past for any start between 01:00 and 01:29 EST on 2026-11-01 in America/New_York with30 1 * * *, and the chained calls walk backwards (05:59Z, 06:00Z, 05:01Z, ...). Regression since 4.1.1 (#966). The scheduling loop itself is not affected, real jobs run through the transition on fake timers fire once and on time.How Has This Been Tested?
The new test in
tests/crontime.test.tspins the clock before the transition withsinon.useFakeTimers, so it fails on main whatever the calendar date says (Expected: true, Received: false) and passes with the fix.npm test(TZ=Europe/Paris) 167 passed,npm run lintclean, Node 20.20.2, luxon 3.7.2.I also compared the patched and unpatched builds against a brute force oracle built from wall clock tables for America/New_York, America/Santiago, Australia/Sydney, Australia/Lord_Howe, Antarctica/Troll and Asia/Seoul across the 2026 and 2027 transitions, about 170k calls with the luxon clock seeded before and after each transition. The guard fires only where the unpatched build went backwards, and never on spring-forward or in a zone without DST.
Types of changes
Checklist:
!after the type/scope in the title (see the Conventional Commits standard).