From 118db52dd432a43dc4592d0ff579203c3cd8deb7 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 14 May 2025 10:04:43 -0700 Subject: [PATCH] Temporal: Add coverage for getTimeZoneTransition edge cases (#4466) getTimeZoneTransition return values should always correspond with UTC offset transitions, not with time zone metadata changes such as making DST permanent or updating abbreviation strings. See: https://github.com/tc39/proposal-temporal/issues/3105 --- .../rule-change-without-offset-transition.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/rule-change-without-offset-transition.js diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/rule-change-without-offset-transition.js b/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/rule-change-without-offset-transition.js new file mode 100644 index 0000000000..6f65592162 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/getTimeZoneTransition/rule-change-without-offset-transition.js @@ -0,0 +1,70 @@ +// Copyright (C) 2022 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition +description: > + Rule changes in the TZDB that do not have offset transtions should not be + returned by getTimeZoneTransition. +features: [Temporal] +---*/ + +// Europe/London changed from DST to permanent British Standard Time on +// 1968-10-27, but the actual UTC offset did not change at that time. +// getTimeZoneTransition should not return an instant on 1968-10-27. + +const londonPrev = new Temporal.ZonedDateTime(0n, "Europe/London") + .getTimeZoneTransition("previous"); +assert.notSameValue( + londonPrev.offsetNanoseconds, + londonPrev.subtract({ nanoseconds: 1 }).offsetNanoseconds, + "should be a UTC offset transition" +); +assert.sameValue( + londonPrev.epochNanoseconds, + -59004000000000000n, + "epoch nanoseconds for 1968-02-18T03:00:00+01:00" +); + +const londonNext = new Temporal.ZonedDateTime(-39488400000000000n /* 1968-10-01T00:00:00+01:00 */, "Europe/London") + .getTimeZoneTransition("next"); +assert.notSameValue( + londonNext.offsetNanoseconds, + londonNext.subtract({ nanoseconds: 1 }).offsetNanoseconds, + "should be a UTC offset transition" +); +assert.sameValue( + londonNext.epochNanoseconds, + 57722400000000000n, + "epoch nanoseconds for 1971-10-31T02:00:00+00:00" +); + +// Similarly, America/Anchorage changed from DST to permanent standard time on +// 1967-04-01. The UTC offset did not change, but the abbreviation did (AST to +// AHST). Still, getTimeZoneTransition should not return an instant on 1967-04-01 + +const anchoragePrev = new Temporal.ZonedDateTime(-84290400000000000n /* 1967-05-01T00:00:00-10:00 */, "America/Anchorage") + .getTimeZoneTransition("previous"); +assert.notSameValue( + anchoragePrev.offsetNanoseconds, + anchoragePrev.subtract({ nanoseconds: 1 }).offsetNanoseconds, + "should be a UTC offset transition" +); +assert.sameValue( + anchoragePrev.epochNanoseconds, + -765378000000000000n, + "epoch nanoseconds for 1945-09-30T01:00:00-10:00" +); + +const anchorageNext = new Temporal.ZonedDateTime(-94658400000000000n /* 1967-01-01T00:00:00-10:00 */, "America/Anchorage") + .getTimeZoneTransition("next"); +assert.notSameValue( + anchorageNext.offsetNanoseconds, + anchorageNext.subtract({ nanoseconds: 1 }).offsetNanoseconds, + "should be a UTC offset transition" +); +assert.sameValue( + anchorageNext.epochNanoseconds, + -21470400000000000n, + "epoch nanoseconds for 1969-04-27T03:00:00-09:00" +);