Skip to content

Commit 49d2309

Browse files
committed
add test how TemporalDuration handles day values around DST transitions and leap seconds
1 parent ff012a3 commit 49d2309

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/builtins/TemporalBuiltinsTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,31 @@ public void testTimeSpecWithOptionalTimeZoneNotAmbiguous() {
10701070
testTrue(code);
10711071
}
10721072

1073+
@Test
1074+
public void testDuration1DayExactly24Hours() {
1075+
// DST was entered on 2022-03-27 at 1am, jumping to 2am
1076+
String code = "var dur = Temporal.Duration.from('P1D');\n" +
1077+
"var relTo = Temporal.ZonedDateTime.from('2022-03-26T12:00+01:00[Europe/Vienna]'); \n" +
1078+
"var dur2 = dur.round({ 'relativeTo': relTo, 'largestUnit': 'seconds' }); \n" +
1079+
"dur2.seconds === 82800;"; // 23 hours
1080+
testTrue(code);
1081+
1082+
// same DST transition as above, but using 24 HOURS instead of 1 DAY
1083+
code = "var dur = Temporal.Duration.from('PT24H');\n" +
1084+
"var relTo = Temporal.ZonedDateTime.from('2022-03-26T12:00+01:00[Europe/Vienna]'); \n" +
1085+
"var dur2 = dur.round({ 'relativeTo': relTo, 'largestUnit': 'seconds' }); \n" +
1086+
"dur2.seconds === 86400;"; // 24 hours, different than above. 1D != 24H
1087+
testTrue(code);
1088+
1089+
// There was one leap second at 2016-12-31 after 23:59:59 (UTC+0)
1090+
code = "var dur = Temporal.Duration.from('P1D');\n" +
1091+
"var relTo = Temporal.ZonedDateTime.from('2016-12-31T12:00:00+00:00[Europe/London]'); \n" +
1092+
"var dur2 = dur.round({ 'relativeTo': relTo, 'largestUnit': 'seconds' }); \n" +
1093+
"dur2.seconds === 86400"; // exactly 1 day; Temporal does not consider leap
1094+
// seconds
1095+
testTrue(code);
1096+
}
1097+
10731098
private static void testTrue(String code) {
10741099
try (Context ctx = getJSContext()) {
10751100
Value result = ctx.eval(ID, code);

0 commit comments

Comments
 (0)