diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js b/js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js new file mode 100644 index 0000000000..23f993f25f --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js @@ -0,0 +1,78 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: > + NormalizedTimeDurationToDays can loop arbitrarily up to max safe integer +info: | + NormalizedTimeDurationToDays ( norm, zonedRelativeTo, timeZoneRec [ , precalculatedPlainDatetime ] ) + ... + 21. Repeat, while done is false, + a. Let oneDayFarther be ? AddDaysToZonedDateTime(relativeResult.[[Instant]], + relativeResult.[[DateTime]], timeZoneRec, zonedRelativeTo.[[Calendar]], sign). + b. Set dayLengthNs to NormalizedTimeDurationFromEpochNanosecondsDifference(oneDayFarther.[[EpochNanoseconds]], + relativeResult.[[EpochNanoseconds]]). + c. Let oneDayLess be ? SubtractNormalizedTimeDuration(norm, dayLengthNs). + c. If NormalizedTimeDurationSign(oneDayLess) × sign ≥ 0, then + i. Set norm to oneDayLess. + ii. Set relativeResult to oneDayFarther. + iii. Set days to days + sign. + d. Else, + i. Set done to true. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const calls = []; +const dayLengthNs = 86400000000000n; +const other = new Temporal.ZonedDateTime(dayLengthNs, "UTC", "iso8601"); + +function createRelativeTo(count) { + const dayInstant = new Temporal.Instant(dayLengthNs); + const substitutions = []; + const timeZone = new Temporal.TimeZone("UTC"); + // Return constant value for first _count_ calls + TemporalHelpers.substituteMethod( + timeZone, + "getPossibleInstantsFor", + substitutions + ); + substitutions.length = count; + let i = 0; + for (i = 0; i < substitutions.length; i++) { + // (this value) + substitutions[i] = [dayInstant]; + } + // Record calls in calls[] + TemporalHelpers.observeMethod(calls, timeZone, "getPossibleInstantsFor"); + return new Temporal.ZonedDateTime(0n, timeZone); +} + +let zdt = createRelativeTo(50); +calls.splice(0); // Reset calls list after ZonedDateTime construction +zdt.since(other, { + largestUnit: "day", +}); +assert.sameValue( + calls.length, + 50 + 1, + "Expected ZonedDateTime.since to call getPossibleInstantsFor correct number of times" +); + +zdt = createRelativeTo(100); +calls.splice(0); // Reset calls list after previous loop + ZonedDateTime construction +zdt.since(other, { + largestUnit: "day", +}); +assert.sameValue( + calls.length, + 100 + 1, + "Expected ZonedDateTime.since to call getPossibleInstantsFor correct number of times" +); + +zdt = createRelativeTo(105); +assert.throws(RangeError, () => zdt.since(other, { largestUnit: "day" }), "105 days > 2⁵³ ns"); + +reportCompare(0, 0); |