mirror of
https://github.com/tc39/test262.git
synced 2025-09-29 21:18:44 +02:00
Several tests in staging use the Pacific/Apia IANA time zone to test the behaviour of various algorithms for the case where Samoa skipped the entire day of Dec. 30, 2011, when they switched from one side of the International Date Line to the other. Since implementations are not technically required to support IANA time zones, add a fake Samoa time zone to TemporalHelpers that has the same transition, and use it in those tests. (The time zone isn't exactly the same as Pacific/Apia, since Samoa also observes DST and this time zone doesn't. It's only the same for this one transition.) See: #3649
57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
/*---
|
|
description: >
|
|
Verify the time zone arithmetic used in
|
|
TemporalHelpers.crossDateLineTimeZone() against the Pacific/Apia time zone in
|
|
the implementation's time zone database
|
|
includes: [compareArray.js, temporalHelpers.js]
|
|
features: [Temporal]
|
|
---*/
|
|
|
|
// No need to test this on hosts that don't provide an Intl object. It's
|
|
// sufficient that the logic is tested on at least one host.
|
|
if (typeof globalThis.Intl !== "undefined") {
|
|
const tz = TemporalHelpers.crossDateLineTimeZone();
|
|
const realTz = new Temporal.TimeZone('Pacific/Apia');
|
|
const shiftInstant = Temporal.Instant.from('2011-12-30T10:00:00Z');
|
|
|
|
assert.sameValue(
|
|
tz.getOffsetNanosecondsFor(shiftInstant),
|
|
realTz.getOffsetNanosecondsFor(shiftInstant),
|
|
'offset at shift instant'
|
|
);
|
|
const minus1 = shiftInstant.subtract({ hours: 1 });
|
|
assert.sameValue(
|
|
tz.getOffsetNanosecondsFor(minus1),
|
|
realTz.getOffsetNanosecondsFor(minus1),
|
|
'offset at 1 hour before shift'
|
|
);
|
|
const plus1 = shiftInstant.add({ hours: 1 });
|
|
assert.sameValue(
|
|
tz.getOffsetNanosecondsFor(plus1),
|
|
realTz.getOffsetNanosecondsFor(plus1),
|
|
'offset at 1 hour after shift'
|
|
);
|
|
|
|
const middleOfSkippedDayWallTime = Temporal.PlainDateTime.from("2011-12-30T12:00");
|
|
assert.compareArray(
|
|
tz.getPossibleInstantsFor(middleOfSkippedDayWallTime).map((i) => i.epochNanoseconds),
|
|
realTz.getPossibleInstantsFor(middleOfSkippedDayWallTime).map((i) => i.epochNanoseconds),
|
|
'possible instants for middle of skipped day wall time'
|
|
);
|
|
const before1 = middleOfSkippedDayWallTime.subtract({ days: 1 });
|
|
assert.compareArray(
|
|
tz.getPossibleInstantsFor(before1).map((i) => i.epochNanoseconds),
|
|
realTz.getPossibleInstantsFor(before1).map((i) => i.epochNanoseconds),
|
|
'possible instants for 1 day before skipped day'
|
|
);
|
|
const after1 = middleOfSkippedDayWallTime.add({ days: 1 });
|
|
assert.compareArray(
|
|
tz.getPossibleInstantsFor(after1).map((i) => i.epochNanoseconds),
|
|
realTz.getPossibleInstantsFor(after1).map((i) => i.epochNanoseconds),
|
|
'possible instants for 1 day after skipped day'
|
|
);
|
|
}
|