| 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.instant.compare |
| 7 |
description: > |
| 8 |
RangeError thrown if an invalid ISO string (or syntactically valid ISO string |
| 9 |
that is not supported) is used as an Instant |
| 10 |
features: [Temporal, arrow-function] |
| 11 |
---*/ |
| 12 |
|
| 13 |
const invalidStrings = [ |
| 14 |
// invalid ISO strings: |
| 15 |
"", |
| 16 |
"invalid iso8601", |
| 17 |
"2020-01-00T00:00Z", |
| 18 |
"2020-01-32T00:00Z", |
| 19 |
"2020-02-30T00:00Z", |
| 20 |
"2021-02-29T00:00Z", |
| 21 |
"2020-00-01T00:00Z", |
| 22 |
"2020-13-01T00:00Z", |
| 23 |
"2020-01-01TZ", |
| 24 |
"2020-01-01T25:00:00Z", |
| 25 |
"2020-01-01T01:60:00Z", |
| 26 |
"2020-01-01T01:60:61Z", |
| 27 |
"2020-01-01T00:00Zjunk", |
| 28 |
"2020-01-01T00:00:00Zjunk", |
| 29 |
"2020-01-01T00:00:00.000000000Zjunk", |
| 30 |
"2020-01-01T00:00:00+00:00junk", |
| 31 |
"2020-01-01T00:00:00+00:00[UTC]junk", |
| 32 |
"2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", |
| 33 |
"02020-01-01T00:00Z", |
| 34 |
"2020-001-01T00:00Z", |
| 35 |
"2020-01-001T00:00Z", |
| 36 |
"2020-01-01T001Z", |
| 37 |
"2020-01-01T01:001Z", |
| 38 |
"2020-01-01T01:01:001Z", |
| 39 |
"2020-01-01T00:00-24:00", |
| 40 |
"2020-01-01T00:00+24:00", |
| 41 |
// valid, but forms not supported in Temporal: |
| 42 |
"2020-W01-1T00:00Z", |
| 43 |
"2020-001T00:00Z", |
| 44 |
"+0002020-01-01T00:00Z", |
| 45 |
// may be valid in other contexts, but insufficient information for Instant: |
| 46 |
"2020-01", |
| 47 |
"+002020-01", |
| 48 |
"01-01", |
| 49 |
"2020-W01", |
| 50 |
"P1Y", |
| 51 |
"-P12Y", |
| 52 |
"2020-01-01", |
| 53 |
"2020-01-01T00", |
| 54 |
"2020-01-01T00:00", |
| 55 |
"2020-01-01T00:00:00", |
| 56 |
"2020-01-01T00:00:00.000000000", |
| 57 |
// valid, but outside the supported range: |
| 58 |
"-999999-01-01T00:00Z", |
| 59 |
"+999999-01-01T00:00Z", |
| 60 |
]; |
| 61 |
|
| 62 |
const epoch = new Temporal.Instant(0n); |
| 63 |
for (const arg of invalidStrings) { |
| 64 |
assert.throws( |
| 65 |
RangeError, |
| 66 |
() => Temporal.Instant.compare(arg, epoch), |
| 67 |
`"${arg}" should not be a valid ISO string for an Instant (first argument)` |
| 68 |
); |
| 69 |
assert.throws( |
| 70 |
RangeError, |
| 71 |
() => Temporal.Instant.compare(epoch, arg), |
| 72 |
`"${arg}" should not be a valid ISO string for an Instant (second argument)` |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
reportCompare(0, 0); |