You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Normative: Prevent indefinite loops in NormalizedTimeDurationToDays
It's possible to make at least the second loop continue indefinitely with
a contrived calendar and time zone.
DRAFT: Still to be determined if this precludes any non-contrived use
cases. If so, we will keep the loops, but still put an upper limit on the
number of iterations.
Includes a few more tests in the NYSE time zone cookbook example to make
sure that a time zone transition of >24h continues to work.
1. Let _relativeResult_ be ? AddDaysToZonedDateTime(_startInstant_, _startDateTime_, _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _days_).
1446
-
1. If _sign_is 1, then
1447
-
1.Repeat, while _days_> 0 and ℝ(_relativeResult_.[[EpochNanoseconds]]) >_endNs_,
1448
-
1. Set _days_ to _days_ - 1.
1449
-
1.Set _relativeResult_ to ? AddDaysToZonedDateTime(_startInstant_, _startDateTime_, _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _days_).
1446
+
1. If _sign_= 1, and _days_> 0, and ℝ(_relativeResult_.[[EpochNanoseconds]]) >_endNs_, then
1447
+
1.Set _days_to _days_ - 1.
1448
+
1. Set _relativeResult_ to ? AddDaysToZonedDateTime(_startInstant_, _startDateTime_, _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _days_).
1449
+
1.If _days_> 0 and ℝ(_relativeResult_.[[EpochNanoseconds]]) >_endNs_, throw a *RangeError* exception.
1450
1450
1. Set _norm_ to NormalizedTimeDurationFromEpochNanosecondsDifference(_endNs_, _relativeResult_.[[EpochNanoseconds]]).
1451
-
1. Let _done_ be *false*.
1452
-
1. Let _dayLengthNs_ be ~unset~.
1453
-
1. Repeat, while _done_ is *false*,
1454
-
1. Let _oneDayFarther_ be ? AddDaysToZonedDateTime(_relativeResult_.[[Instant]], _relativeResult_.[[DateTime]], _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _sign_).
1451
+
1. Let _oneDayFarther_ be ? AddDaysToZonedDateTime(_relativeResult_.[[Instant]], _relativeResult_.[[DateTime]], _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _sign_).
1452
+
1. Let _dayLengthNs_ be NormalizedTimeDurationFromEpochNanosecondsDifference(_oneDayFarther.[[EpochNanoseconds]], _relativeResult_.[[EpochNanoseconds]]).
1453
+
1. Let _oneDayLess_ be ? SubtractNormalizedTimeDuration(_norm_, _dayLengthNs_).
1454
+
1. If NormalizedTimeDurationSign(_oneDayLess_) ×_sign_≥ 0, then
1455
+
1. Set _norm_ to _oneDayLess_.
1456
+
1. Set _relativeResult_ to _oneDayFarther_.
1457
+
1. Set _days_ to _days_ + _sign_.
1458
+
1. Set _oneDayFarther_ to ? AddDaysToZonedDateTime(_relativeResult_.[[Instant]], _relativeResult_.[[DateTime]], _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _sign_).
1455
1459
1. Set _dayLengthNs_ to NormalizedTimeDurationFromEpochNanosecondsDifference(_oneDayFarther.[[EpochNanoseconds]], _relativeResult_.[[EpochNanoseconds]]).
1456
1460
1. If NormalizedTimeDurationSign(? SubtractNormalizedTimeDuration(_norm_, _dayLengthNs_)) ×_sign_≥ 0, then
1457
-
1. Set _norm_ to ? SubtractNormalizedTimeDuration(_norm_, _dayLengthNs_).
1458
-
1. Set _relativeResult_ to _oneDayFarther_.
1459
-
1. Set _days_ to _days_ + _sign_.
1460
-
1. Else,
1461
-
1. Set _done_ to *true*.
1461
+
1. Throw a *RangeError* exception.
1462
1462
1. If _days_< 0 and _sign_ = 1, throw a *RangeError* exception.
1463
1463
1. If _days_> 0 and _sign_ = -1, throw a *RangeError* exception.
1464
1464
1. If NormalizedTimeDurationSign(_norm_) = -1, then
0 commit comments