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.
TODO: 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.
Copy file name to clipboardExpand all lines: spec/zoneddatetime.html
+15-16Lines changed: 15 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -1444,23 +1444,22 @@ <h1>
1444
1444
1. Else if _days_< 0 and _timeSign_< 0, then
1445
1445
1. Set _days_ to _days_ + 1.
1446
1446
1. Let _relativeResult_ be ? AddDaysToZonedDateTime(_startInstant_, _startDateTime_, _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _days_).
1447
-
1. If _sign_is 1, then
1448
-
1.Repeat, while _days_> 0 and ℝ(_relativeResult_.[[EpochNanoseconds]]) >_endNs_,
1449
-
1. Set _days_ to _days_ - 1.
1450
-
1.Set _relativeResult_ to ? AddDaysToZonedDateTime(_startInstant_, _startDateTime_, _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _days_).
1447
+
1. If _sign_= 1, and _days_> 0, and ℝ(_relativeResult_.[[EpochNanoseconds]]) >_endNs_, then
1448
+
1.Set _days_to _days_ - 1.
1449
+
1. Set _relativeResult_ to ? AddDaysToZonedDateTime(_startInstant_, _startDateTime_, _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _days_).
1450
+
1.If _days_> 0 and ℝ(_relativeResult_.[[EpochNanoseconds]]) >_endNs_, throw a *RangeError* exception.
1451
1451
1. Set _norm_ to NormalizedTimeDurationFromEpochNanosecondsDifference(_endNs_, _relativeResult_.[[EpochNanoseconds]]).
1452
-
1. Let _done_ be *false*.
1453
-
1. Let _dayLengthNs_ be ~unset~.
1454
-
1. Repeat, while _done_ is *false*,
1455
-
1. Let _oneDayFarther_ be ? AddDaysToZonedDateTime(_relativeResult_.[[Instant]], _relativeResult_.[[DateTime]], _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _sign_).
1456
-
1. Set _dayLengthNs_ to NormalizedTimeDurationFromEpochNanosecondsDifference(_oneDayFarther_.[[EpochNanoseconds]], _relativeResult_.[[EpochNanoseconds]]).
1457
-
1. Let _oneDayLess_ be ! SubtractNormalizedTimeDuration(_norm_, _dayLengthNs_).
1458
-
1. If NormalizedTimeDurationSign(_oneDayLess_) ×_sign_≥ 0, then
1459
-
1. Set _norm_ to _oneDayLess_.
1460
-
1. Set _relativeResult_ to _oneDayFarther_.
1461
-
1. Set _days_ to _days_ + _sign_.
1462
-
1. Else,
1463
-
1. Set _done_ to *true*.
1452
+
1. Let _oneDayFarther_ be ? AddDaysToZonedDateTime(_relativeResult_.[[Instant]], _relativeResult_.[[DateTime]], _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _sign_).
1453
+
1. Let _dayLengthNs_ be NormalizedTimeDurationFromEpochNanosecondsDifference(_oneDayFarther.[[EpochNanoseconds]], _relativeResult_.[[EpochNanoseconds]]).
1454
+
1. Let _oneDayLess_ be ! SubtractNormalizedTimeDuration(_norm_, _dayLengthNs_).
1455
+
1. If NormalizedTimeDurationSign(_oneDayLess_) ×_sign_≥ 0, then
1456
+
1. Set _norm_ to _oneDayLess_.
1457
+
1. Set _relativeResult_ to _oneDayFarther_.
1458
+
1. Set _days_ to _days_ + _sign_.
1459
+
1. Set _oneDayFarther_ to ? AddDaysToZonedDateTime(_relativeResult_.[[Instant]], _relativeResult_.[[DateTime]], _timeZoneRec_, _zonedRelativeTo_.[[Calendar]], _sign_).
1460
+
1. Set _dayLengthNs_ to NormalizedTimeDurationFromEpochNanosecondsDifference(_oneDayFarther.[[EpochNanoseconds]], _relativeResult_.[[EpochNanoseconds]]).
1461
+
1. If NormalizedTimeDurationSign(? SubtractNormalizedTimeDuration(_norm_, _dayLengthNs_)) ×_sign_≥ 0, then
1462
+
1. Throw a *RangeError* exception.
1464
1463
1. If _days_< 0 and _sign_ = 1, throw a *RangeError* exception.
1465
1464
1. If _days_> 0 and _sign_ = -1, throw a *RangeError* exception.
1466
1465
1. If NormalizedTimeDurationSign(_norm_) = -1, then
0 commit comments