Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/ZonedDateTime/from/argument-string-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 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: ISO strings at the edges of the representable range
8 features: [Temporal]
9 ---*/
10
11 // offset: "use" takes the exact time with the given UTC offset, and so doesn't
12 // need to compute the UTC epoch nanoseconds at the wall-clock time.
13 // offset: "ignore" takes the UTC offset from the time zone, which in the case
14 // of an offset time zone also doesn't need to compute the UTC epoch nanoseconds
15 // at the wall-clock time.
16
17 const validStringsForOffsetUseIgnore = [
18 "-271821-04-20T00:00Z[UTC]",
19 "-271821-04-19T23:00-01:00[-01:00]",
20 "-271821-04-19T00:01-23:59[-23:59]",
21 "+275760-09-13T00:00Z[UTC]",
22 "+275760-09-13T01:00+01:00[+01:00]",
23 "+275760-09-13T23:59+23:59[+23:59]",
24 ];
25
26 for (const offset of ["use", "ignore"]) {
27 for (const arg of validStringsForOffsetUseIgnore) {
28 Temporal.ZonedDateTime.from(arg, { offset: "use" });
29 }
30 }
31
32 // Other values for offset need to compute the UTC epoch nanoseconds at the
33 // wall-clock time, so that can't be outside the representable range even if
34 // the signified exact time is inside.
35
36 const validStringsForOffsetPreferReject = [
37 "-271821-04-20T00:00Z[UTC]",
38 "+275760-09-13T00:00Z[UTC]",
39 "+275760-09-13T01:00+01:00[+01:00]",
40 "+275760-09-13T23:59+23:59[+23:59]",
41 ];
42
43 const invalidStringsForOffsetPreferReject = [
44 "-271821-04-19T23:00-01:00[-01:00]",
45 "-271821-04-19T00:00:01-23:59[-23:59]",
46 ];
47
48 for (const offset of ["prefer", "reject"]) {
49 for (const arg of validStringsForOffsetPreferReject) {
50 Temporal.ZonedDateTime.from(arg, { offset });
51 }
52
53 for (const arg of invalidStringsForOffsetPreferReject) {
54 assert.throws(
55 RangeError,
56 () => Temporal.ZonedDateTime.from(arg, { offset }),
57 `wall-clock time of "${arg}" is outside the representable range of ZonedDateTime (offset=${offset})`
58 );
59 }
60 }
61
62 const invalidStrings = [
63 "-271821-04-19T23:59:59.999999999Z[UTC]",
64 "-271821-04-19T23:00-00:59[-00:59]",
65 "-271821-04-19T00:00:00-23:59[-23:59]",
66 "+275760-09-13T00:00:00.000000001Z[UTC]",
67 "+275760-09-13T01:00+00:59[+00:59]",
68 "+275760-09-14T00:00+23:59[+23:59]",
69 ];
70
71 for (const offset of ["use", "ignore", "prefer", "reject"]) {
72 for (const arg of invalidStrings) {
73 assert.throws(
74 RangeError,
75 () => Temporal.ZonedDateTime.from(arg, { offset }),
76 `"${arg}" is outside the representable range of ZonedDateTime (offset=${offset})`
77 );
78 }
79 }
80
81 reportCompare(0, 0);