Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/ZonedDateTime/compare/argument-string-date-with-utc-offset.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) 2022 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: UTC offset not valid with format that does not include a time
8 features: [Temporal]
9 ---*/
10
11 const validStrings = [
12 "1970-01-01T00Z[UTC]",
13 "1970-01-01T00Z[!UTC]",
14 "1970-01-01T00+00:00[UTC]",
15 "1970-01-01T00+00:00[!UTC]",
16 ];
17
18 for (const arg of validStrings) {
19 const result = Temporal.ZonedDateTime.compare(arg, arg);
20
21 assert.sameValue(
22 result,
23 0,
24 `"${arg}" is a valid UTC offset with time for ZonedDateTime`
25 );
26 }
27
28 const invalidStrings = [
29 "2022-09-15Z[UTC]",
30 "2022-09-15Z[Europe/Vienna]",
31 "2022-09-15+00:00[UTC]",
32 "2022-09-15-02:30[America/St_Johns]",
33 ];
34 const datetime = new Temporal.ZonedDateTime(0n, "UTC");
35
36 for (const arg of invalidStrings) {
37 assert.throws(
38 RangeError,
39 () => Temporal.ZonedDateTime.compare(arg, datetime),
40 `"${arg}" UTC offset without time is not valid for ZonedDateTime (first argument)`
41 );
42 assert.throws(
43 RangeError,
44 () => Temporal.ZonedDateTime.compare(datetime, arg),
45 `"${arg}" UTC offset without time is not valid for ZonedDateTime (second argument)`
46 );
47 }
48
49 reportCompare(0, 0);