Polyfill: Validate result in UTC fast path in GetPossibleEpochNanoseconds - #367
Closed
craig-o-curtis wants to merge 1 commit into
Closed
craig-o-curtis wants to merge 1 commit into
craig-o-curtis wants to merge 1 commit into
Conversation
…onds The `IsValidEpochNanoseconds` check was previously omitted when the time zone was UTC. NOTE: (this info below wasn't in the upstream commit) Ports tc39/proposal-temporal#3205, which fixed tc39/proposal-temporal#3203. Near the end of the supported range, a calculation in UTC that needs a date-time after the maximum Instant returned a result instead of throwing a RangeError. The "+00:00" and named time zone paths already threw. For example, this returned 0 and now throws a RangeError: new Temporal.Duration(0).total({ unit: 'days', relativeTo: '+275760-09-12T23:59:60+00:00[UTC]' }) UPSTREAM_COMMIT=d90d432b2ff10ffc4149dd0ba8f0aece21150adc
craig-o-curtis
force-pushed
the
port-3205-validate-utc-fast-path
branch
from
September 18, 2026 07:59
b0d2111 to
d1f5911
Compare
This was referenced Sep 18, 2026
Contributor
|
Thanks for proactively porting this, but I'd prefer to keep the commits ported in order — otherwise the rebases become unmanageable. I apologize that it's been taking a while. |
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.
Ports one tc39/proposal-temporal commit:
GetPossibleEpochNanosecondsdoes not validate the result tc39/proposal-temporal#3203)What was wrong
GetPossibleEpochNanosecondshas a fast path for theUTCtime zone, and that path skipped theIsValidEpochNanosecondscheck the other paths make. So near the end of the supported range, a calculation in UTC that needs a date-time after the maximum Instant (+275760-09-13T00:00:00Z) returned a result instead of throwing a RangeError. Onmain, each of these returns a value:The same calls with
+00:00orEurope/Londonin place ofUTCalready throw a RangeError onmain.What this changes
The UTC fast path now checks its result with
ValidateEpochNanoseconds, like the other paths. All three calls above throwRangeError: date/time value is outside of supported range, the same as with+00:00.Results inside the range don't change. In both
UTCand+00:00, these give the same results onmainand on this branch:PlainDateTimeat the maximum converted toZonedDateTime, and one nanosecond past it (which throws).until()near the maximum without rounding (P3DT5H).PT23Htotal in days relative to one day before the maximum (0.9583333333333334).startOfDay()at the maximum.until()(P1DT2H).Not fixed by this PR
This problem has nothing to do with UTC, but it is also near the maximum Instant. It behaves the same on
mainand on this branch. Within one search window of the maximum Instant,getTimeZoneTransition('next')can miss a transition that exists, and code that depends on it then throws:GetNamedTimeZoneNextTransitionin proposal-temporal's polyfill has the same code, so I'll report it there first.Testing
Node 24.21.0 (ICU 78.3, CLDR 48):
NODE_ENV=productionbuilds: 4828 passed, 0 failed, 0 passed unexpectedly.The test262 test for this fix,
built-ins/Temporal/Duration/prototype/total/relativeto-date-limits.js, is newer than our pinned test262. It got its UTC case in tc39/test262@416f2a3de8, which also postdates proposal-temporal's test262 pin when #3205 merged. I ran it by hand at that commit, along with its siblingDuration/prototype/round/relativeto-date-limits.js:total/relativeto-date-limits.jsround/relativeto-date-limits.jsmainDifferences from upstream (TypeScript)
None. The change is the same three lines as upstream's.