| 1 |
// |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2021 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: Conversion of ISO date-time strings to Temporal.Instant instances |
| 8 |
features: [Temporal] |
| 9 |
---*/ |
| 10 |
|
| 11 |
const epoch = new Temporal.Instant(0n); |
| 12 |
const hourBefore = new Temporal.Instant(-3600_000_000_000n); |
| 13 |
|
| 14 |
let str = "1970-01-01T00:00"; |
| 15 |
assert.throws(RangeError, () => Temporal.Instant.compare(str, epoch), "bare date-time string is not an instant (first argument)"); |
| 16 |
assert.throws(RangeError, () => Temporal.Instant.compare(epoch, str), "bare date-time string is not an instant (second argument)"); |
| 17 |
str = "1970-01-01T00:00[UTC]"; |
| 18 |
assert.throws(RangeError, () => Temporal.Instant.compare(str, epoch), "date-time + IANA annotation is not an instant (first argument)"); |
| 19 |
assert.throws(RangeError, () => Temporal.Instant.compare(epoch, str), "date-time + IANA annotation is not an instant (second argument)"); |
| 20 |
|
| 21 |
str = "1970-01-01T00:00Z"; |
| 22 |
assert.sameValue(Temporal.Instant.compare(str, epoch), 0, "date-time + Z preserves exact time (first argument)"); |
| 23 |
assert.sameValue(Temporal.Instant.compare(epoch, str), 0, "date-time + Z preserves exact time (second argument)"); |
| 24 |
|
| 25 |
str = "1970-01-01T00:00+01:00"; |
| 26 |
assert.sameValue(Temporal.Instant.compare(str, hourBefore), 0, "date-time + offset preserves exact time with offset (first argument)"); |
| 27 |
assert.sameValue(Temporal.Instant.compare(hourBefore, str), 0, "date-time + offset preserves exact time with offset (second argument)"); |
| 28 |
|
| 29 |
str = "1970-01-01T00:00Z[Etc/Ignored]"; |
| 30 |
assert.sameValue(Temporal.Instant.compare(str, epoch), 0, "date-time + Z + IANA annotation ignores the IANA annotation (first argument)"); |
| 31 |
assert.sameValue(Temporal.Instant.compare(epoch, str), 0, "date-time + Z + IANA annotation ignores the IANA annotation (second argument)"); |
| 32 |
|
| 33 |
str = "1970-01-01T00:00+01:00[Etc/Ignored]"; |
| 34 |
assert.sameValue(Temporal.Instant.compare(str, hourBefore), 0, "date-time + offset + IANA annotation ignores the IANA annotation (first argument)"); |
| 35 |
assert.sameValue(Temporal.Instant.compare(hourBefore, str), 0, "date-time + offset + IANA annotation ignores the IANA annotation (second argument)"); |
| 36 |
|
| 37 |
str = "1970-01-01T00:00Z[u-ca=hebrew]"; |
| 38 |
assert.sameValue(Temporal.Instant.compare(str, epoch), 0, "date-time + Z + Calendar ignores the Calendar (first argument)"); |
| 39 |
assert.sameValue(Temporal.Instant.compare(epoch, str), 0, "date-time + Z + Calendar ignores the Calendar (second argument)"); |
| 40 |
|
| 41 |
str = "1970-01-01T00:00+01:00[u-ca=hebrew]"; |
| 42 |
assert.sameValue(Temporal.Instant.compare(str, hourBefore), 0, "date-time + offset + Calendar ignores the Calendar (first argument)"); |
| 43 |
assert.sameValue(Temporal.Instant.compare(hourBefore, str), 0, "date-time + offset + Calendar ignores the Calendar (second argument)"); |
| 44 |
|
| 45 |
str = "1970-01-01T00:00+01:00[Etc/Ignored][u-ca=hebrew]"; |
| 46 |
assert.sameValue(Temporal.Instant.compare(str, hourBefore), 0, "date-time + offset + IANA annotation + Calendar ignores the IANA annotation and the Calendar (first argument)"); |
| 47 |
assert.sameValue(Temporal.Instant.compare(hourBefore, str), 0, "date-time + offset + IANA annotation + Calendar ignores the IANA annotation and the Calendar (second argument)"); |
| 48 |
|
| 49 |
reportCompare(0, 0); |