diff --git a/test/built-ins/Temporal/Duration/prototype/round/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/Duration/prototype/round/calendar-dateadd-called-with-options-undefined.js index 3d16c0dd5c6..56f26a8523d 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/calendar-dateadd-called-with-options-undefined.js +++ b/test/built-ins/Temporal/Duration/prototype/round/calendar-dateadd-called-with-options-undefined.js @@ -24,7 +24,7 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar); const instance1 = new Temporal.Duration(1, 1, 1, 1, 1); instance1.round({ smallestUnit: "weeks", relativeTo }); -assert.sameValue(calendar.dateAddCallCount, 3, "rounding with calendar smallestUnit"); +assert.sameValue(calendar.dateAddCallCount, 4, "rounding with calendar smallestUnit"); // Rounding with a non-default largestUnit to cover the path in // UnbalanceDurationRelative where larger units are converted into smaller @@ -41,7 +41,7 @@ calendar.dateAddCallCount = 0; const instance2 = new Temporal.Duration(0, 1, 1, 1); instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo }); -assert.sameValue(calendar.dateAddCallCount, 5, "rounding with non-default largestUnit and calendar smallestUnit"); +assert.sameValue(calendar.dateAddCallCount, 6, "rounding with non-default largestUnit and calendar smallestUnit"); // Rounding with smallestUnit days only. // The calls come from these paths: @@ -54,4 +54,4 @@ calendar.dateAddCallCount = 0; const instance3 = new Temporal.Duration(1, 1, 1, 1, 1); instance3.round({ smallestUnit: "days", relativeTo }); -assert.sameValue(calendar.dateAddCallCount, 2, "rounding with days smallestUnit"); +assert.sameValue(calendar.dateAddCallCount, 3, "rounding with days smallestUnit"); diff --git a/test/built-ins/Temporal/Duration/prototype/round/dst-balancing-result.js b/test/built-ins/Temporal/Duration/prototype/round/dst-balancing-result.js new file mode 100644 index 00000000000..40b360238f8 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/dst-balancing-result.js @@ -0,0 +1,24 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.duration.prototype.round +description: > + Balancing the resulting duration takes the time zone's UTC offset shifts + into account +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const timeZone = TemporalHelpers.springForwardFallBackTimeZone(); + +// Based on a test case by Adam Shaw +{ + const duration = new Temporal.Duration(1, 0, 0, 0, 24); + const relativeTo = new Temporal.ZonedDateTime( + 941184000_000_000_000n /* = 1999-10-29T08Z */, + timeZone); /* = 1999-10-29T00-08 in local time */ + + const result = duration.round({ largestUnit: "years", relativeTo }); + TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, + "24 hours does not balance to 1 day in 25-hour day"); +} diff --git a/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js b/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js index b42a868e632..dc62d661b2a 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js @@ -394,6 +394,9 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ "call options.relativeTo.calendar.dateUntil", // 12.n "call options.relativeTo.calendar.dateAdd", // 12.r MoveRelativeDate "call options.relativeTo.calendar.dateAdd", // 12.x MoveRelativeDate + // MoveRelativeZonedDateTime → AddZonedDateTime + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.timeZone.getPossibleInstantsFor", // BalanceDateDurationRelative "call options.relativeTo.calendar.dateAdd", // 9.c "call options.relativeTo.calendar.dateUntil", // 9.d @@ -420,6 +423,9 @@ const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor // RoundDuration "call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate + // MoveRelativeZonedDateTime → AddZonedDateTime + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.timeZone.getPossibleInstantsFor", // BalanceDateDurationRelative "call options.relativeTo.calendar.dateAdd", // 10.d "call options.relativeTo.calendar.dateUntil", // 10.e @@ -445,6 +451,9 @@ const expectedOpsForWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([ "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor // RoundDuration "call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate + // MoveRelativeZonedDateTime → AddZonedDateTime + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.timeZone.getPossibleInstantsFor", ]); new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "months", smallestUnit: "weeks", relativeTo: zonedRelativeTo })); assert.compareArray( diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js index 1ef0125cb28..99ba61bb4b8 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js @@ -53,4 +53,4 @@ const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuilti const instance = new Temporal.Duration(1, 0, 0, 0, 24); instance.round({ largestUnit: "years", relativeTo }); -assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); +assert.sameValue(timeZone.calls, 8, "getPossibleInstantsFor should have been called 8 times"); diff --git a/test/built-ins/Temporal/Duration/prototype/round/timezone-getpossibleinstantsfor-iterable.js b/test/built-ins/Temporal/Duration/prototype/round/timezone-getpossibleinstantsfor-iterable.js index 1838425cb15..26d685aba63 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/timezone-getpossibleinstantsfor-iterable.js +++ b/test/built-ins/Temporal/Duration/prototype/round/timezone-getpossibleinstantsfor-iterable.js @@ -36,6 +36,7 @@ const expected = [ "2000-01-01T00:00:00", // called once on the input relativeTo object "2001-02-09T00:00:00", // called once on relativeTo plus years, months, weeks, days from the receiver "2001-02-10T00:00:00", // called once on the previous value plus the calendar days difference between that and the time part of the duration + "2001-02-01T00:00:00", // called once in the balancing step on intermediate relativeTo ]; TemporalHelpers.checkTimeZonePossibleInstantsIterable((timeZone) => { diff --git a/test/built-ins/Temporal/Duration/prototype/total/dst-balancing-result.js b/test/built-ins/Temporal/Duration/prototype/total/dst-balancing-result.js new file mode 100644 index 00000000000..132c68589cc --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/total/dst-balancing-result.js @@ -0,0 +1,21 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.duration.prototype.total +description: > + Balancing the resulting duration takes the time zone's UTC offset shifts + into account +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +// Based on a test case by Adam Shaw + +const duration = new Temporal.Duration(1, 0, 0, 0, 24); +const timeZone = TemporalHelpers.springForwardFallBackTimeZone(); +const relativeTo = new Temporal.ZonedDateTime( + 941184000_000_000_000n /* = 1999-10-29T08Z */, + timeZone); /* = 1999-10-29T00-08 in local time */ + +const result = duration.total({ unit: "days", relativeTo }); +assert.sameValue(result, 366.96, "24 hours does not balance to 1 day in 25-hour day"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/dst-balancing-result.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/dst-balancing-result.js new file mode 100644 index 00000000000..1cca27eb9ee --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/dst-balancing-result.js @@ -0,0 +1,26 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: > + Balancing the resulting duration takes the time zone's UTC offset shifts + into account +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const timeZone = TemporalHelpers.springForwardFallBackTimeZone(); + +// Based on a test case by Adam Shaw +{ + const start = new Temporal.ZonedDateTime( + 941184000_000_000_000n /* = 1999-10-29T08Z */, + timeZone); /* = 1999-10-29T00-08 in local time */ + const end = new Temporal.ZonedDateTime( + 972889200_000_000_000n /* = 2000-10-30T07Z */, + timeZone); /* = 2000-10-29T23-08 in local time */ + + const duration = start.since(end, { largestUnit: "years" }); + TemporalHelpers.assertDuration(duration, -1, 0, 0, 0, -24, 0, 0, 0, 0, 0, + "24 hours does not balance to 1 day in 25-hour day"); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/dst-balancing-result.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/dst-balancing-result.js new file mode 100644 index 00000000000..0bdf261f09d --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/dst-balancing-result.js @@ -0,0 +1,26 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: > + Balancing the resulting duration takes the time zone's UTC offset shifts + into account +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const timeZone = TemporalHelpers.springForwardFallBackTimeZone(); + +// Based on a test case by Adam Shaw +{ + const start = new Temporal.ZonedDateTime( + 941184000_000_000_000n /* = 1999-10-29T08Z */, + timeZone); /* = 1999-10-29T00-08 in local time */ + const end = new Temporal.ZonedDateTime( + 972889200_000_000_000n /* = 2000-10-30T07Z */, + timeZone); /* = 2000-10-29T23-08 in local time */ + + const duration = start.until(end, { largestUnit: "years" }); + TemporalHelpers.assertDuration(duration, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, + "24 hours does not balance to 1 day in 25-hour day"); +} diff --git a/test/intl402/Temporal/Duration/prototype/round/relativeto-string-datetime.js b/test/intl402/Temporal/Duration/prototype/round/relativeto-string-datetime.js index 3d4f118549c..3ec0960f4f0 100644 --- a/test/intl402/Temporal/Duration/prototype/round/relativeto-string-datetime.js +++ b/test/intl402/Temporal/Duration/prototype/round/relativeto-string-datetime.js @@ -14,15 +14,15 @@ const instance = new Temporal.Duration(1, 0, 0, 0, 24); let relativeTo = "2019-11-01T00:00[America/Vancouver]"; const result4 = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); +TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00Z[America/Vancouver]"; const result5 = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result5, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); +TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00-07:00[America/Vancouver]"; const result6 = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result6, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); +TemporalHelpers.assertDuration(result6, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); relativeTo = "2019-11-01T00:00+04:15[America/Vancouver]"; assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch");