From 2f06e0b6b35d34773ef8ce9c1b8b843734bfada1 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Tue, 23 Sep 2025 15:56:43 -0400 Subject: [PATCH] Tests for Temporal issue 3141 (#4568) * tests for Temporal issue 3141 * added test descriptions * Temporal tests for total/round related to bug 3141 * tweak tests, fix wording * don't use unnecessary temporalHelpers * update tests to include Temporal issues 3148 and 3149 * move tests, update descriptions * rename some other files * move new Temporal tests into intl-land * Actually commit ptomato typo change requests --- .../round/relativeto-dst-back-transition.js | 106 ++++++++++++++++++ .../total/relativeto-dst-back-transition.js | 65 +++++++++++ .../since/same-date-reverse-wallclock.js | 36 ++++++ .../until/same-date-reverse-wallclock.js | 36 ++++++ 4 files changed, 243 insertions(+) create mode 100644 test/intl402/Temporal/Duration/prototype/round/relativeto-dst-back-transition.js create mode 100644 test/intl402/Temporal/Duration/prototype/total/relativeto-dst-back-transition.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/since/same-date-reverse-wallclock.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/until/same-date-reverse-wallclock.js diff --git a/test/intl402/Temporal/Duration/prototype/round/relativeto-dst-back-transition.js b/test/intl402/Temporal/Duration/prototype/round/relativeto-dst-back-transition.js new file mode 100644 index 0000000000..b845c86b41 --- /dev/null +++ b/test/intl402/Temporal/Duration/prototype/round/relativeto-dst-back-transition.js @@ -0,0 +1,106 @@ +// Copyright (C) 2025 Adam Shaw. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Ensures correct rounding results when relativeTo is within the second wallclock occurence of a + DST fall-back transition. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +/* +Addresses https://github.com/tc39/proposal-temporal/issues/3149 +(NudgeToCalendarUnit wrong span) +*/ +{ + // the second 01:00 time in the DST transition. 01:00-07:00 happens just before this + const origin = Temporal.ZonedDateTime.from('2025-11-02T01:00:00-08:00[America/Vancouver]'); + const dur = Temporal.Duration.from({ hours: 11, minutes: 30 }); + const roundedDur = dur.round({ + largestUnit: 'days', + smallestUnit: 'days', + relativeTo: origin, + roundingMode: 'halfExpand', + }); + TemporalHelpers.assertDuration( + roundedDur, + 0, 0, 0, /* days = */ 0, 0, 0, 0, 0, 0, 0, + 'relativeTo in fall-back DST transition, second wallclock time, assumed 24 hour span when +1 day', + ); +} + +/* +Addresses https://github.com/tc39/proposal-temporal/issues/3149 +(NudgeToCalendarUnit wrong span) +*/ +{ + // the second 01:00 time in the DST transition. 01:00-07:00 happens just before this + const origin = Temporal.ZonedDateTime.from('2025-11-02T01:00:00-08:00[America/Vancouver]'); + const dur = Temporal.Duration.from({ hours: -12, minutes: -30 }); + const roundedDur = dur.round({ + largestUnit: 'days', + smallestUnit: 'days', + relativeTo: origin, + roundingMode: 'halfExpand', + }); + TemporalHelpers.assertDuration( + roundedDur, + 0, 0, 0, /* days = */ -1, 0, 0, 0, 0, 0, 0, + 'relativeTo in fall-back DST transition, second wallclock time, assumed 25 hour span when -1 day', + ); +} + +/* +Related to https://github.com/tc39/proposal-temporal/issues/3141 +(DifferenceZonedDateTime assertion) +*/ +TemporalHelpers.assertDuration( + Temporal.Duration.from({ minutes: -59 }).round({ + smallestUnit: 'days', + relativeTo: '2025-11-02T01:00:00-08:00[America/Vancouver]', + }), + 0, 0, 0, /* days = */ 0, 0, 0, 0, 0, 0, 0, + 'negative delta from relativeTo, positive wallclock delta', +); + +/* +Related to https://github.com/tc39/proposal-temporal/issues/3141 +(DifferenceZonedDateTime assertion) +*/ +TemporalHelpers.assertDuration( + Temporal.Duration.from({ minutes: -59 }).round({ + smallestUnit: 'days', + relativeTo: '2025-11-02T01:00:00-08:00[America/Vancouver]', + roundingMode: 'expand', + }), + 0, 0, 0, /* days = */ -1, 0, 0, 0, 0, 0, 0, + 'negative delta from relativeTo, positive wallclock delta, expanding', +); + +/* +Related to https://github.com/tc39/proposal-temporal/issues/3141 +(DifferenceZonedDateTime assertion) +*/ +TemporalHelpers.assertDuration( + Temporal.Duration.from({ minutes: 59 }).round({ + smallestUnit: 'days', + relativeTo: '2025-11-02T01:01:00-07:00[America/Vancouver]', + }), + 0, 0, 0, /* days = */ 0, 0, 0, 0, 0, 0, 0, + 'positive delta from relativeTo, negative wallclock delta', +); + +/* +Related to https://github.com/tc39/proposal-temporal/issues/3141 +(DifferenceZonedDateTime assertion) +*/ +TemporalHelpers.assertDuration( + Temporal.Duration.from({ minutes: 59 }).round({ + smallestUnit: 'days', + relativeTo: '2025-11-02T01:01:00-07:00[America/Vancouver]', + roundingMode: 'expand', + }), + 0, 0, 0, /* days = */ 1, 0, 0, 0, 0, 0, 0, + 'positive delta from relativeTo, negative wallclock delta, expanding', +); diff --git a/test/intl402/Temporal/Duration/prototype/total/relativeto-dst-back-transition.js b/test/intl402/Temporal/Duration/prototype/total/relativeto-dst-back-transition.js new file mode 100644 index 0000000000..efcd06a336 --- /dev/null +++ b/test/intl402/Temporal/Duration/prototype/total/relativeto-dst-back-transition.js @@ -0,0 +1,65 @@ +// Copyright (C) 2025 Adam Shaw. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Ensures correct total results when relativeTo is within the second wallclock occurence of a + DST fall-back transition. +features: [Temporal] +---*/ + +/* +Addresses https://github.com/tc39/proposal-temporal/issues/3148 +(NudgeToCalendarUnit wrong span) +*/ +{ + const origin = Temporal.ZonedDateTime.from('2025-11-02T01:00:00-08:00[America/Vancouver]'); + const dur = Temporal.Duration.from({ hours: 2 }); + const total = dur.total({ unit: 'days', relativeTo: origin }); + assert.sameValue( + total, + 2 / 24, + 'relativeTo in fall-back DST transition, second wallclock time, assumed 24 hour span when +1 day', + ); +} + +/* +Addresses https://github.com/tc39/proposal-temporal/issues/3148 +(NudgeToCalendarUnit wrong span) +*/ +{ + const origin = Temporal.ZonedDateTime.from('2025-11-02T01:00:00-08:00[America/Vancouver]'); + const dur = Temporal.Duration.from({ hours: -2 }); + const total = dur.total({ unit: 'days', relativeTo: origin }); + assert.sameValue( + total, + -2 / 25, + 'relativeTo in fall-back DST transition, second wallclock time, assumed 25 hour span when -1 day', + ); +} + +/* +Related to https://github.com/tc39/proposal-temporal/issues/3141 +(DifferenceZonedDateTime assertion) +*/ +assert.sameValue( + Temporal.Duration.from({ minutes: -59 }).total({ + unit: 'days', + relativeTo: '2025-11-02T01:00:00-08:00[America/Vancouver]', + }), + -59 / (60 * 25), // 25 hour span when adding -1 day to relativeTo + 'negative delta from relativeTo, positive wallclock delta', +); + +/* +Related to https://github.com/tc39/proposal-temporal/issues/3141 +(DifferenceZonedDateTime assertion) +*/ +assert.sameValue( + Temporal.Duration.from({ minutes: 59 }).total({ + unit: 'days', + relativeTo: '2025-11-02T01:01:00-07:00[America/Vancouver]', + }), + 59 / (60 * 25), // 25 hour span when adding +1 day to relativeTo + 'positive delta from relativeTo, negative wallclock delta', +); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/since/same-date-reverse-wallclock.js b/test/intl402/Temporal/ZonedDateTime/prototype/since/same-date-reverse-wallclock.js new file mode 100644 index 0000000000..356b459337 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/since/same-date-reverse-wallclock.js @@ -0,0 +1,36 @@ +// Copyright (C) 2025 Adam Shaw. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Returns a simple nanosecond time-duration when ISO year-month-day is same-day + and wall-clock delta direction is the reverse of the epoch-nanosecond direction +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +/* +Addresses https://github.com/tc39/proposal-temporal/issues/3141 +*/ + +TemporalHelpers.assertDuration( + Temporal.ZonedDateTime + .from('2025-11-02T01:00:00-08:00[America/Vancouver]') // later + .since('2025-11-02T01:01:00-07:00[America/Vancouver]', { // earlier + largestUnit: 'year', + smallestUnit: 'millisecond', + }), + 0, 0, 0, 0, 0, /* minutes = */ 59, 0, 0, 0, 0, + 'same-day, positive epoch-nanoseconds delta, negative wall-clock delta', +) + +TemporalHelpers.assertDuration( + Temporal.ZonedDateTime + .from('2025-11-02T01:01:00-07:00[America/Vancouver]') // earlier + .since('2025-11-02T01:00:00-08:00[America/Vancouver]', { // later + largestUnit: 'year', + smallestUnit: 'millisecond', + }), + 0, 0, 0, 0, 0, /* minutes = */ -59, 0, 0, 0, 0, + 'same-day, negative epoch-nanoseconds delta, positive wall-clock delta', +) diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/until/same-date-reverse-wallclock.js b/test/intl402/Temporal/ZonedDateTime/prototype/until/same-date-reverse-wallclock.js new file mode 100644 index 0000000000..206c80c708 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/until/same-date-reverse-wallclock.js @@ -0,0 +1,36 @@ +// Copyright (C) 2025 Adam Shaw. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Returns a simple nanosecond time-duration when ISO year-month-day is same-day + and wall-clock delta direction is the reverse of the epoch-nanosecond direction +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +/* +Addresses https://github.com/tc39/proposal-temporal/issues/3141 +*/ + +TemporalHelpers.assertDuration( + Temporal.ZonedDateTime + .from('2025-11-02T01:00:00-08:00[America/Vancouver]') // later + .until('2025-11-02T01:01:00-07:00[America/Vancouver]', { // earlier + largestUnit: 'year', + smallestUnit: 'nanosecond', + }), + 0, 0, 0, 0, 0, /* minutes = */ -59, 0, 0, 0, 0, + 'same-day, negative epoch-nanoseconds delta, positive wall-clock delta', +) + +TemporalHelpers.assertDuration( + Temporal.ZonedDateTime + .from('2025-11-02T01:01:00-07:00[America/Vancouver]') // earlier + .until('2025-11-02T01:00:00-08:00[America/Vancouver]', { // later + largestUnit: 'year', + smallestUnit: 'nanosecond', + }), + 0, 0, 0, 0, 0, /* minutes = */ 59, 0, 0, 0, 0, + 'same-day, positive epoch-nanoseconds delta, negative wall-clock delta', +)