-
Notifications
You must be signed in to change notification settings - Fork 153
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
Normative: Check for invalid epoch nanoseconds in Temporal.TimeZone.prototype.get{Next,Previous}Transition #2311
Conversation
…rototype.get{Next,Previous}Transition `GetIANATimeZoneNextTransition` and `GetIANATimeZonePreviousTransition` aren't required to return an epoch nanoseconds value which is within the supported range, therefore we have to call `IsValidEpochNanoseconds` before invoking `CreateTemporalInstant`.
Codecov Report
@@ Coverage Diff @@
## main #2311 +/- ##
=======================================
Coverage 91.08% 91.08%
=======================================
Files 19 19
Lines 10566 10566
Branches 1695 1695
=======================================
Hits 9624 9624
Misses 932 932
Partials 10 10
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
@@ -308,6 +308,7 @@ <h1>Temporal.TimeZone.prototype.getNextTransition ( _startingPoint_ )</h1> | |||
1. If _timeZone_.[[OffsetNanoseconds]] is not *undefined*, return *null*. | |||
1. Let _transition_ be GetIANATimeZoneNextTransition(_startingPoint_.[[Nanoseconds]], _timeZone_.[[Identifier]]). | |||
1. If _transition_ is *null*, return *null*. | |||
1. If ! IsValidEpochNanoseconds(_transition_) is *false*, throw a *RangeError* exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have gone for returning null, but either way it doesn't really matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also define the GetIANATimeZone...Transition ops so that they guarantee not to return an out-of-range time and return null instead. That seems more in line with what e.g. SystemUTCEpochNanoseconds does; it clamps the value to the range. Clamping wouldn't be appropriate here, I think, but returning null would. We did receive guidance specifically during the Stage 3 reviews of this proposal not to throw, so it seems in any case that we shouldn't throw here either.
I think both options are probably fine. There's a slight semantic difference:
Returning let instant = startInstant;
while (instant !== null) {
// Use `instant`.
instant = tz.getNextTransition(instant);
} When an error is thrown, we'd need to wrap the call into a let instant = startInstant;
while (instant !== null) {
// Use `instant`.
try {
instant = tz.getNextTransition(instant);
} catch {
instant = null;
}
} But then again going through all transitions seems a rather unlikely case to happen in practice. |
IMO we should not throw an errors for built-in time zones like this. The system is supposed to be reliable! So I'd definitely recommend Or should we go further and add an assertion that the implementation must not return out-of-range values from built-in time zone implementations? |
Meeting 2022-07-07: we should prevent the internal GetIANATimeZone{Previous,Next}Transition operations from returning epoch nanoseconds that are out of range. Therefore I will close this PR and open a new one that fixes the issue that way. |
→ #2351 |
GetIANATimeZoneNextTransition
andGetIANATimeZonePreviousTransition
aren't required to return an epoch nanoseconds value which is within the
supported range, therefore we have to call
IsValidEpochNanoseconds
before invoking
CreateTemporalInstant
.