mirror of
https://github.com/tc39/test262.git
synced 2025-07-31 01:44:54 +02:00
This requires a few adjustments of time zone names and offsets in some places. The only named time zone that is required to be supported by an implementation not supporting ECMA-402 is "UTC".
30 lines
1.3 KiB
JavaScript
30 lines
1.3 KiB
JavaScript
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
/*---
|
|
esid: sec-temporal.instant.from
|
|
description: Conversion of ISO date-time strings to Temporal.Instant instances
|
|
features: [Temporal]
|
|
---*/
|
|
|
|
let str = "1970-01-01T00:00";
|
|
assert.throws(RangeError, () => Temporal.Instant.from(str), "bare date-time string is not an instant");
|
|
str = "1970-01-01T00:00[UTC]";
|
|
assert.throws(RangeError, () => Temporal.Instant.from(str), "date-time + IANA annotation is not an instant");
|
|
|
|
str = "1970-01-01T00:00Z";
|
|
const result1 = Temporal.Instant.from(str);
|
|
assert.sameValue(result1.epochNanoseconds, 0n, "date-time + Z preserves exact time");
|
|
|
|
str = "1970-01-01T00:00+01:00";
|
|
const result2 = Temporal.Instant.from(str);
|
|
assert.sameValue(result2.epochNanoseconds, -3600_000_000_000n, "date-time + offset preserves exact time with offset");
|
|
|
|
str = "1970-01-01T00:00Z[Etc/Ignored]";
|
|
const result3 = Temporal.Instant.from(str);
|
|
assert.sameValue(result3.epochNanoseconds, 0n, "date-time + Z + IANA annotation ignores the IANA annotation");
|
|
|
|
str = "1970-01-01T00:00+01:00[Etc/Ignored]";
|
|
const result4 = Temporal.Instant.from(str);
|
|
assert.sameValue(result4.epochNanoseconds, -3600_000_000_000n, "date-time + offset + IANA annotation ignores the IANA annotation");
|