Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/ZonedDateTime/compare/zoneddatetime-string.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) 2021 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-temporal.zoneddatetime.compare
7 description: Conversion of ISO date-time strings to Temporal.ZonedDateTime instances
8 features: [Temporal]
9 ---*/
10
11 const epoch = new Temporal.ZonedDateTime(0n, "UTC");
12 const hourBefore = new Temporal.ZonedDateTime(-3600_000_000_000n, "UTC");
13
14 let str = "1970-01-01T00:00";
15 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(str, epoch), "bare date-time string is not a ZonedDateTime (first argument)");
16 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(epoch, str), "bare date-time string is not a ZonedDateTime (second argument)");
17 str = "1970-01-01T00:00Z";
18 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(str, epoch), "date-time + Z is not a ZonedDateTime (first argument)");
19 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(epoch, str), "date-time + Z is not a ZonedDateTime (second argument)");
20 str = "1970-01-01T00:00+01:00";
21 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(str, epoch), "date-time + offset is not a ZonedDateTime (first argument)");
22 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(epoch, str), "date-time + offset is not a ZonedDateTime (second argument)");
23
24 str = "1970-01-01T00:00[+01:00]";
25 const result1 = Temporal.ZonedDateTime.compare(str, hourBefore);
26 assert.sameValue(result1, 0, "date-time + IANA annotation preserves wall time in the time zone (first argument)");
27 const result2 = Temporal.ZonedDateTime.compare(hourBefore, str);
28 assert.sameValue(result2, 0, "date-time + IANA annotation preserves wall time in the time zone (second argument)");
29
30 str = "1970-01-01T00:00Z[+01:00]";
31 const result3 = Temporal.ZonedDateTime.compare(str, epoch);
32 assert.sameValue(result3, 0, "date-time + Z + IANA annotation preserves exact time in the time zone (first argument)");
33 const result4 = Temporal.ZonedDateTime.compare(epoch, str);
34 assert.sameValue(result4, 0, "date-time + Z + IANA annotation preserves exact time in the time zone (second argument)");
35
36 str = "1970-01-01T00:00+01:00[+01:00]";
37 const result5 = Temporal.ZonedDateTime.compare(str, hourBefore);
38 assert.sameValue(result5, 0, "date-time + offset + IANA annotation ensures both exact and wall time match (first argument)");
39 const result6 = Temporal.ZonedDateTime.compare(hourBefore, str);
40 assert.sameValue(result6, 0, "date-time + offset + IANA annotation ensures both exact and wall time match (second argument)");
41
42 str = "1970-01-01T00:00-04:15[+01:00]";
43 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(str, epoch), "date-time + offset + IANA annotation throws if wall time and exact time mismatch (first argument)");
44 assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(epoch, str), "date-time + offset + IANA annotation throws if wall time and exact time mismatch (second argument)");
45
46 reportCompare(0, 0);