| 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.from |
| 7 |
description: Conversion of ISO date-time strings to Temporal.Instant instances |
| 8 |
features: [Temporal] |
| 9 |
---*/ |
| 10 |
|
| 11 |
let str = "1970-01-01T00:00"; |
| 12 |
assert.throws(RangeError, () => Temporal.Instant.from(str), "bare date-time string is not an instant"); |
| 13 |
str = "1970-01-01T00:00[UTC]"; |
| 14 |
assert.throws(RangeError, () => Temporal.Instant.from(str), "date-time + IANA annotation is not an instant"); |
| 15 |
|
| 16 |
str = "1970-01-01T00:00Z"; |
| 17 |
const result1 = Temporal.Instant.from(str); |
| 18 |
assert.sameValue(result1.epochNanoseconds, 0n, "date-time + Z preserves exact time"); |
| 19 |
|
| 20 |
str = "1970-01-01T00:00+01:00"; |
| 21 |
const result2 = Temporal.Instant.from(str); |
| 22 |
assert.sameValue(result2.epochNanoseconds, -3600_000_000_000n, "date-time + offset preserves exact time with offset"); |
| 23 |
|
| 24 |
str = "1970-01-01T00:00Z[Etc/Ignored]"; |
| 25 |
const result3 = Temporal.Instant.from(str); |
| 26 |
assert.sameValue(result3.epochNanoseconds, 0n, "date-time + Z + IANA annotation ignores the IANA annotation"); |
| 27 |
|
| 28 |
str = "1970-01-01T00:00+01:00[Etc/Ignored]"; |
| 29 |
const result4 = Temporal.Instant.from(str); |
| 30 |
assert.sameValue(result4.epochNanoseconds, -3600_000_000_000n, "date-time + offset + IANA annotation ignores the IANA annotation"); |
| 31 |
|
| 32 |
str = "1970-01-01T00:00Z[u-ca=hebrew]"; |
| 33 |
const result6 = Temporal.Instant.from(str); |
| 34 |
assert.sameValue(result6.epochNanoseconds, 0n, "date-time + Z + Calendar ignores the Calendar"); |
| 35 |
|
| 36 |
str = "1970-01-01T00:00+01:00[u-ca=hebrew]"; |
| 37 |
const result7 = Temporal.Instant.from(str); |
| 38 |
assert.sameValue(result7.epochNanoseconds, -3600_000_000_000n, "date-time + offset + Calendar ignores the Calendar"); |
| 39 |
|
| 40 |
str = "1970-01-01T00:00+01:00[Etc/Ignored][u-ca=hebrew]"; |
| 41 |
const result8 = Temporal.Instant.from(str); |
| 42 |
assert.sameValue(result8.epochNanoseconds, -3600_000_000_000n, "date-time + offset + IANA annotation + Calendar ignores the Calendar and IANA annotation"); |
| 43 |
|
| 44 |
reportCompare(0, 0); |