From 7d31aa21ad6385f83c74393a255c354beaa666aa Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 28 Jul 2022 15:55:29 -0700 Subject: [PATCH] Temporal: Add basic IANA-time-zone-aware tests for TimeZone.getPlainDateTimeFor This adds several tests for values that should be produced by the time zone database and should not be subject to change in the future. This tests basic functionality of TimeZone.getPlainDateTimeFor with an IANA time zone database. --- .../prototype/getPlainDateTimeFor/basic.js | 78 +++++++++++++++++++ .../prototype/getPlainDateTimeFor/dst.js | 25 ++++++ 2 files changed, 103 insertions(+) create mode 100644 test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/basic.js create mode 100644 test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst.js diff --git a/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/basic.js b/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/basic.js new file mode 100644 index 0000000000..aaa7f82ddd --- /dev/null +++ b/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/basic.js @@ -0,0 +1,78 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getplaindatetimefor +description: Sample of results for IANA time zones +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +function test(epochNs, results) { + const instant = new Temporal.Instant(epochNs); + Object.entries(results).forEach(([id, expected]) => { + const tz = new Temporal.TimeZone(id); + const dt = tz.getPlainDateTimeFor(instant); + TemporalHelpers.assertPlainDateTime(dt, ...expected, `Local time of ${instant} in ${id}`); + }); +} + +// Unix epoch +test(0n, { + 'America/Los_Angeles': [1969, 12, "M12", 31, 16, 0, 0, 0, 0, 0], + 'America/New_York': [1969, 12, "M12", 31, 19, 0, 0, 0, 0, 0], + 'Africa/Monrovia': [1969, 12, "M12", 31, 23, 15, 30, 0, 0, 0], + 'Europe/London': [1970, 1, "M01", 1, 1, 0, 0, 0, 0, 0], + 'Europe/Berlin': [1970, 1, "M01", 1, 1, 0, 0, 0, 0, 0], + 'Europe/Moscow': [1970, 1, "M01", 1, 3, 0, 0, 0, 0, 0], + 'Asia/Kolkata': [1970, 1, "M01", 1, 5, 30, 0, 0, 0, 0], + 'Asia/Tokyo': [1970, 1, "M01", 1, 9, 0, 0, 0, 0, 0], +}); + +// Just before epoch +test(-1n, { + 'America/Los_Angeles': [1969, 12, "M12", 31, 15, 59, 59, 999, 999, 999], + 'America/New_York': [1969, 12, "M12", 31, 18, 59, 59, 999, 999, 999], + 'Africa/Monrovia': [1969, 12, "M12", 31, 23, 15, 29, 999, 999, 999], + 'Europe/London': [1970, 1, "M01", 1, 0, 59, 59, 999, 999, 999], + 'Europe/Berlin': [1970, 1, "M01", 1, 0, 59, 59, 999, 999, 999], + 'Europe/Moscow': [1970, 1, "M01", 1, 2, 59, 59, 999, 999, 999], + 'Asia/Kolkata': [1970, 1, "M01", 1, 5, 29, 59, 999, 999, 999], + 'Asia/Tokyo': [1970, 1, "M01", 1, 8, 59, 59, 999, 999, 999], +}); + +// Just after epoch +test(1n, { + 'America/Los_Angeles': [1969, 12, "M12", 31, 16, 0, 0, 0, 0, 1], + 'America/New_York': [1969, 12, "M12", 31, 19, 0, 0, 0, 0, 1], + 'Africa/Monrovia': [1969, 12, "M12", 31, 23, 15, 30, 0, 0, 1], + 'Europe/London': [1970, 1, "M01", 1, 1, 0, 0, 0, 0, 1], + 'Europe/Berlin': [1970, 1, "M01", 1, 1, 0, 0, 0, 0, 1], + 'Europe/Moscow': [1970, 1, "M01", 1, 3, 0, 0, 0, 0, 1], + 'Asia/Kolkata': [1970, 1, "M01", 1, 5, 30, 0, 0, 0, 1], + 'Asia/Tokyo': [1970, 1, "M01", 1, 9, 0, 0, 0, 0, 1], +}); + +// Hours before epoch +test(-6300_000_000_001n, { + 'America/Los_Angeles': [1969, 12, "M12", 31, 14, 14, 59, 999, 999, 999], + 'America/New_York': [1969, 12, "M12", 31, 17, 14, 59, 999, 999, 999], + 'Africa/Monrovia': [1969, 12, "M12", 31, 21, 30, 29, 999, 999, 999], + 'Europe/London': [1969, 12, "M12", 31, 23, 14, 59, 999, 999, 999], + 'Europe/Berlin': [1969, 12, "M12", 31, 23, 14, 59, 999, 999, 999], + 'Europe/Moscow': [1970, 1, "M01", 1, 1, 14, 59, 999, 999, 999], + 'Asia/Kolkata': [1970, 1, "M01", 1, 3, 44, 59, 999, 999, 999], + 'Asia/Tokyo': [1970, 1, "M01", 1, 7, 14, 59, 999, 999, 999], +}); + +// Hours after epoch +test(6300_000_000_001n, { + 'America/Los_Angeles': [1969, 12, "M12", 31, 17, 45, 0, 0, 0, 1], + 'America/New_York': [1969, 12, "M12", 31, 20, 45, 0, 0, 0, 1], + 'Africa/Monrovia': [1970, 1, "M01", 1, 1, 0, 30, 0, 0, 1], + 'Europe/London': [1970, 1, "M01", 1, 2, 45, 0, 0, 0, 1], + 'Europe/Berlin': [1970, 1, "M01", 1, 2, 45, 0, 0, 0, 1], + 'Europe/Moscow': [1970, 1, "M01", 1, 4, 45, 0, 0, 0, 1], + 'Asia/Kolkata': [1970, 1, "M01", 1, 7, 15, 0, 0, 0, 1], + 'Asia/Tokyo': [1970, 1, "M01", 1, 10, 45, 0, 0, 0, 1], +}); diff --git a/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst.js b/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst.js new file mode 100644 index 0000000000..dea36e2dcd --- /dev/null +++ b/test/intl402/Temporal/TimeZone/prototype/getPlainDateTimeFor/dst.js @@ -0,0 +1,25 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getplaindatetimefor +description: Sample of results for IANA time zones around DST changes +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +function test(epochNs, id, expected) { + const instant = new Temporal.Instant(epochNs); + const tz = new Temporal.TimeZone(id); + const dt = tz.getPlainDateTimeFor(instant); + TemporalHelpers.assertPlainDateTime(dt, ...expected, `Local time of ${instant} in ${id}`); +} + +// Just before DST forward shift +test(1553993999_999_999_999n, "Europe/London", [2019, 3, "M03", 31, 0, 59, 59, 999, 999, 999]); +// Just after DST forward shift +test(1553994000_000_000_000n, "Europe/London", [2019, 3, "M03", 31, 2, 0, 0, 0, 0, 0]); +// Just before DST backward shift +test(1550368799_999_999_999n, "America/Sao_Paulo", [2019, 2, "M02", 16, 23, 59, 59, 999, 999, 999]); +// Just after DST backward shift +test(1550368800_000_000_000n, "America/Sao_Paulo", [2019, 2, "M02", 16, 23, 0, 0, 0, 0, 0]);