Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/Duration/compare/throws-when-target-zoned-date-time-outside-valid-limits.js

raw
1 // |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2024 André Bargull. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-temporal.duration.compare
7 description: >
8 Throws RangeError when adding duration to ZonedDateTime relativeTo fails.
9 info: |
10 Temporal.Duration.compare ( one, two [ , options ] )
11
12 12. If zonedRelativeTo is not undefined, and either TemporalUnitCategory(largestUnit1)
13 or TemporalUnitCategory(largestUnit2) is date, then
14 ...
15 c. Let after1 be ? AddZonedDateTime(zonedRelativeTo.[[EpochNanoseconds]], timeZone,
16 calendar, duration1, constrain).
17 d. Let after2 be ? AddZonedDateTime(zonedRelativeTo.[[EpochNanoseconds]], timeZone,
18 calendar, duration2, constrain).
19 ...
20 features: [Temporal]
21 ---*/
22
23 var blank = new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
24 var oneDay = new Temporal.Duration(0, 0, 0, 1);
25
26 var relativeTo = new Temporal.ZonedDateTime(864n * 10n**19n, "UTC");
27
28 var options = {
29 relativeTo
30 };
31
32 assert.throws(RangeError, () => Temporal.Duration.compare(oneDay, blank, options));
33 assert.throws(RangeError, () => Temporal.Duration.compare(blank, oneDay, options));
34
35 reportCompare(0, 0);