summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-out-of-range-forward-offset-shift.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
commit59203c63bb777a3bacec32fb8830fba33540e809 (patch)
tree58298e711c0ff0575818c30485b44a2f21bf28a0 /js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-out-of-range-forward-offset-shift.js
parentAdding upstream version 126.0.1. (diff)
downloadfirefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz
firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-out-of-range-forward-offset-shift.js')
-rw-r--r--js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-out-of-range-forward-offset-shift.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-out-of-range-forward-offset-shift.js b/js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-out-of-range-forward-offset-shift.js
new file mode 100644
index 0000000000..cbfca704c2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-out-of-range-forward-offset-shift.js
@@ -0,0 +1,46 @@
+// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
+// Copyright (C) 2024 Igalia, S.L. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-temporal.duration.prototype.compare
+description: >
+ UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor
+ in DisambiguatePossibleInstants cannot be greater than 24 hours.
+features: [Temporal]
+info: |
+ DisambiguatePossibleInstants:
+ 18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception.
+---*/
+
+class ShiftLonger24Hour extends Temporal.TimeZone {
+ id = 'TestTimeZone';
+ _shiftEpochNs = 12n * 3600n * 1_000_000_000n; // 1970-01-01T12:00Z
+
+ constructor() {
+ super('UTC');
+ }
+
+ getOffsetNanosecondsFor(instant) {
+ if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9;
+ return 12 * 3600e9 + 1;
+ }
+
+ getPossibleInstantsFor(plainDateTime) {
+ const [utcInstant] = super.getPossibleInstantsFor(plainDateTime);
+ const { year, month, day } = plainDateTime;
+
+ if (year < 1970) return [utcInstant.subtract({ hours: 12 })];
+ if (year === 1970 && month === 1 && day === 1) return [];
+ return [utcInstant.add({ hours: 12, nanoseconds: 1 })];
+ }
+}
+
+const timeZone = new ShiftLonger24Hour();
+const relativeTo = { year: 1970, month: 1, day: 1, hour: 12, timeZone };
+const duration1 = new Temporal.Duration(1);
+const duration2 = new Temporal.Duration(2);
+
+assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, {relativeTo: relativeTo}), "RangeError should be thrown");
+
+reportCompare(0, 0);