Skip to content

Commit a366023

Browse files
committed
Temporal: Add coverage for getTimeZoneTransition edge cases
A "time zone transition" that is supposed to be returned by this method, is defined in the spec as an exact time where the UTC offset differs from that of the previous exact time value. Implementations reported ambiguity around rule changes in the TZDB that did not actually result in a UTC offset change. For example, a time zone changing its abbreviation, or making DST permanent. Add a test case that checks that the method does not return faulty values that would not satisfy the spec requirement of a UTC offset change. See: tc39/proposal-temporal#3105
1 parent 27622d7 commit a366023

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (C) 2022 André Bargull. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
6+
description: >
7+
Rule changes in the TZDB that do not have offset transtions should not be
8+
returned by getTimeZoneTransition.
9+
features: [Temporal]
10+
---*/
11+
12+
// Europe/London changed from DST to permanent British Standard Time on
13+
// 1968-10-27, but the actual UTC offset did not change at that time.
14+
// getTimeZoneTransition should not return an instant on 1968-10-27.
15+
16+
const londonPrev = new Temporal.ZonedDateTime(0n, "Europe/London")
17+
.getTimeZoneTransition("previous");
18+
assert.notSameValue(
19+
londonPrev.offsetNanoseconds,
20+
londonPrev.subtract({ nanoseconds: 1 }).offsetNanoseconds,
21+
"should be a UTC offset transition"
22+
);
23+
assert.sameValue(
24+
londonPrev.epochNanoseconds,
25+
-59004000000000000n,
26+
"epoch nanoseconds for 1968-02-18T03:00:00+01:00"
27+
);
28+
29+
const londonNext = new Temporal.ZonedDateTime(-39488400000000000n /* 1968-10-01T00:00:00+01:00 */, "Europe/London")
30+
.getTimeZoneTransition("next");
31+
assert.notSameValue(
32+
londonNext.offsetNanoseconds,
33+
londonNext.subtract({ nanoseconds: 1 }).offsetNanoseconds,
34+
"should be a UTC offset transition"
35+
);
36+
assert.sameValue(
37+
londonNext.epochNanoseconds,
38+
57722400000000000n,
39+
"epoch nanoseconds for 1971-10-31T02:00:00+00:00"
40+
);
41+
42+
// Similarly, America/Anchorage changed from DST to permanent standard time on
43+
// 1967-04-01. The UTC offset did not change, but the abbreviation did (AST to
44+
// AHST). Still, getTimeZoneTransition should not return an instant on 1967-04-01
45+
46+
const anchoragePrev = new Temporal.ZonedDateTime(-84290400000000000n /* 1967-05-01T00:00:00-10:00 */, "America/Anchorage")
47+
.getTimeZoneTransition("previous");
48+
assert.notSameValue(
49+
anchoragePrev.offsetNanoseconds,
50+
anchoragePrev.subtract({ nanoseconds: 1 }).offsetNanoseconds,
51+
"should be a UTC offset transition"
52+
);
53+
assert.sameValue(
54+
anchoragePrev.epochNanoseconds,
55+
-765378000000000000n,
56+
"epoch nanoseconds for 1945-09-30T01:00:00-10:00"
57+
);
58+
59+
const anchorageNext = new Temporal.ZonedDateTime(-94658400000000000n /* 1967-01-01T00:00:00-10:00 */, "America/Anchorage")
60+
.getTimeZoneTransition("next");
61+
assert.notSameValue(
62+
anchorageNext.offsetNanoseconds,
63+
anchorageNext.subtract({ nanoseconds: 1 }).offsetNanoseconds,
64+
"should be a UTC offset transition"
65+
);
66+
assert.sameValue(
67+
anchorageNext.epochNanoseconds,
68+
-21470400000000000n,
69+
"epoch nanoseconds for 1969-04-27T03:00:00-09:00"
70+
);

0 commit comments

Comments
 (0)