| 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.plaintime.compare |
| 7 |
description: UTC offset not valid with format that does not include a time |
| 8 |
features: [Temporal] |
| 9 |
---*/ |
| 10 |
|
| 11 |
const validStrings = [ |
| 12 |
"12:34:56.987654321+00:00", |
| 13 |
"12:34:56.987654321+00:00[UTC]", |
| 14 |
"12:34:56.987654321+00:00[!UTC]", |
| 15 |
"12:34:56.987654321-02:30[America/St_Johns]", |
| 16 |
"1976-11-18T12:34:56.987654321+00:00", |
| 17 |
"1976-11-18T12:34:56.987654321+00:00[UTC]", |
| 18 |
"1976-11-18T12:34:56.987654321+00:00[!UTC]", |
| 19 |
"1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", |
| 20 |
]; |
| 21 |
|
| 22 |
for (const arg of validStrings) { |
| 23 |
const result = Temporal.PlainTime.compare(arg, arg); |
| 24 |
|
| 25 |
assert.sameValue( |
| 26 |
result, |
| 27 |
0, |
| 28 |
`"${arg}" is a valid UTC offset with time for PlainTime` |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
const invalidStrings = [ |
| 33 |
"2022-09-15Z", |
| 34 |
"2022-09-15Z[UTC]", |
| 35 |
"2022-09-15Z[Europe/Vienna]", |
| 36 |
"2022-09-15+00:00", |
| 37 |
"2022-09-15+00:00[UTC]", |
| 38 |
"2022-09-15-02:30", |
| 39 |
"2022-09-15-02:30[America/St_Johns]", |
| 40 |
]; |
| 41 |
|
| 42 |
for (const arg of invalidStrings) { |
| 43 |
assert.throws( |
| 44 |
RangeError, |
| 45 |
() => Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)), |
| 46 |
`"${arg}" UTC offset without time is not valid for PlainTime (first argument)` |
| 47 |
); |
| 48 |
assert.throws( |
| 49 |
RangeError, |
| 50 |
() => Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg), |
| 51 |
`"${arg}" UTC offset without time is not valid for PlainTime (second argument)` |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
reportCompare(0, 0); |