Debian Codegraph @

js/src/tests/test262/intl402/Temporal/ZonedDateTime/from/etc-timezone.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.from
7 description: Some Etc/GMT{+/-}{0}N timezones are valid, but not all
8 features: [Temporal, canonical-tz]
9 ---*/
10
11 // "Etc/GMT-0" through "Etc/GMT-14" are OK
12
13 const fields = { year: 1970, month: 1, day: 1 };
14
15 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].forEach((n) => {
16 const tz = "Etc/GMT-" + n;
17 const instance = Temporal.ZonedDateTime.from({ ...fields, timeZone: tz });
18 assert.sameValue(
19 instance.timeZoneId,
20 tz,
21 tz + " is a valid timezone"
22 );
23 });
24
25 const gmtMinus24TZ = "Etc/GMT-24";
26 assert.throws(
27 RangeError,
28 () => Temporal.ZonedDateTime.from({ ...fields, timeZone: gmtMinus24TZ }),
29 gmtMinus24TZ + " is an invalid timezone"
30 );
31
32 // "Etc/GMT-0N" is not OK (1 ≤ N ≤ 9)
33 [1, 2, 3, 4, 5, 6, 7, 8, 9].forEach((n) => {
34 const tz = "Etc/GMT-0" + n;
35 assert.throws(
36 RangeError,
37 () => Temporal.ZonedDateTime.from({ ...fields, timeZone: tz }),
38 tz + " is an invalid timezone"
39 );
40 });
41
42 // "Etc/GMT+0N" is not OK (0 ≤ N ≤ 9)
43 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach((n) => {
44 const tz = "Etc/GMT+0" + n;
45 assert.throws(
46 RangeError,
47 () => Temporal.ZonedDateTime.from({ ...fields, timeZone: tz }),
48 tz + " is an invalid timezone"
49 );
50 });
51
52 // "Etc/GMT+0" through "Etc/GMT+12" are OK
53
54 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].forEach((n) => {
55 const tz = "Etc/GMT+" + n;
56 const instance = Temporal.ZonedDateTime.from({ ...fields, timeZone: tz });
57 assert.sameValue(
58 instance.timeZoneId,
59 tz,
60 tz + " is a valid timezone"
61 );
62 });
63
64 const gmtPlus24TZ = "Etc/GMT+24";
65 assert.throws(
66 RangeError,
67 () => Temporal.ZonedDateTime.from({ ...fields, timeZone: gmtPlus24TZ }),
68 gmtPlus24TZ + " is an invalid timezone"
69 );
70
71 reportCompare(0, 0);