From 01dcb158899a8b80901f4dba4f54bdfd4db0510d Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 8 Feb 2024 11:49:56 -0800 Subject: [PATCH] Temporal: Tests for round() and since()/until() using the same code path This should produce all the same results (except for a change to weeks balancing in round(), which is now more consistent with since()/until()) but leads to different observable user code calls. See https://github.com/tc39/proposal-temporal/issues/2742 --- ...r-dateadd-called-with-options-undefined.js | 43 ++-- ...euntil-called-with-singular-largestunit.js | 14 +- .../prototype/round/dateuntil-field.js | 3 +- ...-time-duration-to-days-loop-arbitrarily.js | 17 +- .../prototype/round/order-of-operations.js | 187 ++++++++++-------- ...nstantsfor-called-with-iso8601-calendar.js | 2 +- ...ized-time-duration-to-days-range-errors.js | 15 +- .../prototype/round/roundingmode-ceil.js | 2 +- .../prototype/round/roundingmode-expand.js | 2 +- .../prototype/round/roundingmode-floor.js | 2 +- .../prototype/round/roundingmode-halfCeil.js | 2 +- .../prototype/round/roundingmode-halfEven.js | 2 +- .../round/roundingmode-halfExpand.js | 2 +- .../prototype/round/roundingmode-halfFloor.js | 2 +- .../prototype/round/roundingmode-halfTrunc.js | 2 +- .../prototype/round/roundingmode-trunc.js | 2 +- ...-duration-relative-when-sign-mismatched.js | 35 ---- ...imezone-getpossibleinstantsfor-iterable.js | 5 +- ...r-dateadd-called-with-options-undefined.js | 15 +- ...euntil-called-with-singular-largestunit.js | 6 +- .../prototype/total/dateuntil-field.js | 1 + ...-time-duration-to-days-loop-arbitrarily.js | 15 +- .../prototype/total/order-of-operations.js | 172 +++++++++------- .../precision-exact-mathematical-values-3.js | 38 ++-- .../precision-exact-mathematical-values-4.js | 14 +- ...nstantsfor-called-with-iso8601-calendar.js | 2 +- ...ized-time-duration-to-days-range-errors.js | 3 + ...-time-duration-to-days-loop-arbitrarily.js | 16 +- ...ized-time-duration-to-days-range-errors.js | 2 +- ...-time-duration-to-days-loop-arbitrarily.js | 16 +- ...ized-time-duration-to-days-range-errors.js | 2 +- test/staging/Temporal/Duration/old/round.js | 4 +- 32 files changed, 326 insertions(+), 319 deletions(-) delete mode 100644 test/built-ins/Temporal/Duration/prototype/round/throws-in-unbalance-duration-relative-when-sign-mismatched.js 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 56f26a8523d..9a3cc3a1d56 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 @@ -17,41 +17,26 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar); // Rounding with smallestUnit a calendar unit. // The calls come from these paths: // Duration.round() -> -// RoundDuration -> -// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd() -// MoveRelativeDate -> calendar.dateAdd() -// BalanceDateDurationRelative -> calendar.dateAdd() +// AddZonedDateTime -> calendar.dateAdd() +// DifferenceZonedDateTimeWithRounding -> +// RoundDuration -> +// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd() +// MoveRelativeDate -> calendar.dateAdd() (2x) +// BalanceDateDurationRelative -> calendar.dateAdd() -const instance1 = new Temporal.Duration(1, 1, 1, 1, 1); -instance1.round({ smallestUnit: "weeks", relativeTo }); -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 -// units; and with a smallestUnit larger than days to cover the path in -// RoundDuration where days are converted into larger units. -// The calls come from these paths: -// Duration.round() -> -// UnbalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd() -// RoundDuration -> MoveRelativeDate -> calendar.dateAdd() (2x) -// BalanceDateDurationRelative -> calendar.dateAdd() -// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd() - -calendar.dateAddCallCount = 0; - -const instance2 = new Temporal.Duration(0, 1, 1, 1); -instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo }); -assert.sameValue(calendar.dateAddCallCount, 6, "rounding with non-default largestUnit and calendar smallestUnit"); +const instance = new Temporal.Duration(1, 1, 1, 1, 1); +instance.round({ smallestUnit: "weeks", relativeTo }); +assert.sameValue(calendar.dateAddCallCount, 5, "rounding with calendar smallestUnit"); // Rounding with smallestUnit days only. // The calls come from these paths: // Duration.round() -> -// RoundDuration -> -// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd() -// BalanceDateDurationRelative -> calendar.dateAdd() +// AddZonedDateTime -> calendar.dateAdd() +// DifferenceZonedDateTimeWithRounding -> +// RoundDuration -> MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd() +// BalanceDateDurationRelative -> calendar.dateAdd() calendar.dateAddCallCount = 0; -const instance3 = new Temporal.Duration(1, 1, 1, 1, 1); -instance3.round({ smallestUnit: "days", relativeTo }); +instance.round({ smallestUnit: "days", relativeTo }); assert.sameValue(calendar.dateAddCallCount, 3, "rounding with days smallestUnit"); diff --git a/test/built-ins/Temporal/Duration/prototype/round/calendar-dateuntil-called-with-singular-largestunit.js b/test/built-ins/Temporal/Duration/prototype/round/calendar-dateuntil-called-with-singular-largestunit.js index 918c1951295..12022268365 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/calendar-dateuntil-called-with-singular-largestunit.js +++ b/test/built-ins/Temporal/Duration/prototype/round/calendar-dateuntil-called-with-singular-largestunit.js @@ -99,9 +99,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular( duration.round({ largestUnit, roundingIncrement: 2, roundingMode: 'ceil', relativeTo }); }, { - years: ["year", "year"], - months: ["month", "month"], - weeks: ["week", "week"], + years: ["year", "year", "year"], + months: ["month", "month", "month"], + weeks: ["week", "week", "week"], days: [], hours: [], minutes: [], @@ -123,7 +123,7 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular( }, { years: ["year"], - months: ["month", "month"], + months: ["month"], weeks: ["week"], days: [], hours: [], @@ -146,9 +146,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular( const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar); duration.round({ largestUnit, smallestUnit: largestUnit, relativeTo }); }, { - years: ["year"], - months: ["month"], - weeks: ["week", "week"], + years: ["year", "year"], + months: ["month", "month"], + weeks: ["week", "week", "week"], days: [] } ); diff --git a/test/built-ins/Temporal/Duration/prototype/round/dateuntil-field.js b/test/built-ins/Temporal/Duration/prototype/round/dateuntil-field.js index 7220d69aedb..39c2c2e9056 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/dateuntil-field.js +++ b/test/built-ins/Temporal/Duration/prototype/round/dateuntil-field.js @@ -28,8 +28,7 @@ const calendar = new CalendarDateUntilObservable("iso8601"); const relativeTo = new Temporal.PlainDate(2018, 10, 12, calendar); const expected = [ - "call dateUntil", // UnbalanceDateDurationRelative - "call dateUntil", // BalanceDateDurationRelative + "call dateUntil", // DifferencePlainDateTimeWithRounding -> DifferenceISODateTime ]; const years = new Temporal.Duration(2); diff --git a/test/built-ins/Temporal/Duration/prototype/round/normalized-time-duration-to-days-loop-arbitrarily.js b/test/built-ins/Temporal/Duration/prototype/round/normalized-time-duration-to-days-loop-arbitrarily.js index c07cd587f72..f44f420f2c5 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/normalized-time-duration-to-days-loop-arbitrarily.js +++ b/test/built-ins/Temporal/Duration/prototype/round/normalized-time-duration-to-days-loop-arbitrarily.js @@ -18,7 +18,7 @@ info: | features: [Temporal] ---*/ -const duration = Temporal.Duration.from({ days: 1 }); +const duration = new Temporal.Duration(0, 0, 1, 1, 1); const dayLengthNs = 86400000000000n; const dayInstant = new Temporal.Instant(dayLengthNs); @@ -35,10 +35,11 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone); assert.throws(RangeError, () => duration.round({ smallestUnit: "days", relativeTo }), "indefinite loop is prevented"); assert.sameValue(calls, 5, "getPossibleInstantsFor is not called indefinitely"); // Expected calls: - // RoundDuration -> MoveRelativeZonedDateTime -> AddZonedDateTime (1) - // BalanceTimeDurationRelative -> - // AddZonedDateTime (2) - // NormalizedTimeDurationToDays -> - // AddDaysToZonedDateTime (3, step 12) - // AddDaysToZonedDateTime (4, step 15) - // AddDaysToZonedDateTime (5, step 18.d) + // AddZonedDateTime (1) + // DifferenceZonedDateTimeWithRounding -> + // DifferenceZonedDateTime -> GetInstantFor (2) + // RoundDuration -> + // MoveRelativeZonedDateTime -> AddZonedDateTime (3) + // NormalizedTimeDurationToDays -> + // AddDaysToZonedDateTime (5, step 18) + // AddDaysToZonedDateTime (6, step 21.d) 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 dc62d661b2a..2833e51ffc9 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 @@ -122,25 +122,30 @@ actual.splice(0); // clear // code path through RoundDuration that rounds to the nearest year, with minimal calendar calls: const expectedMinimalOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([ - // 7.e and 7.g not called because years, months, weeks are 0 - "call options.relativeTo.calendar.dateUntil", // 7.o - // 7.s not called because years, months, weeks are 0 - "call options.relativeTo.calendar.dateAdd", // 7.y MoveRelativeDate + // initial AddDate in Duration.p.round 39.c not called because no calendar units + "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime + // RoundDuration 10.b and 10.d not called because years, months, weeks are 0 + "call options.relativeTo.calendar.dateUntil", // 10.l + // 10.p not called because years = 0 + "call options.relativeTo.calendar.dateAdd", // 10.v ]); -instance.round(createOptionsObserver({ smallestUnit: "years", relativeTo: plainRelativeTo })); +const instanceMinimal = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 100); +instanceMinimal.round(createOptionsObserver({ smallestUnit: "years", relativeTo: plainRelativeTo })); assert.compareArray(actual, expectedMinimalOpsForYearRounding, "order of operations with years = 0 and smallestUnit = years"); actual.splice(0); // clear -// code path through RoundDuration that rounds to the nearest year: +// code path through Duration.prototype.round that rounds to the nearest year: const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 12.d - "call options.relativeTo.calendar.dateAdd", // 12.f - "call options.relativeTo.calendar.dateUntil", // 12.n - "call options.relativeTo.calendar.dateAdd", // 12.r MoveRelativeDate - "call options.relativeTo.calendar.dateAdd", // 12.x MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 39.c + "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime + // RoundDuration + "call options.relativeTo.calendar.dateAdd", // 10.b + "call options.relativeTo.calendar.dateAdd", // 10.d + "call options.relativeTo.calendar.dateUntil", // 10.l + "call options.relativeTo.calendar.dateAdd", // 10.v MoveRelativeDate // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 9.c - "call options.relativeTo.calendar.dateUntil", // 9.d + "call options.relativeTo.calendar.dateAdd", // 8.c + "call options.relativeTo.calendar.dateUntil", // 8.d ]); const instanceYears = new Temporal.Duration(1, 12, 0, 0, /* hours = */ 2400); instanceYears.round(createOptionsObserver({ smallestUnit: "years", relativeTo: plainRelativeTo })); @@ -149,18 +154,16 @@ actual.splice(0); // clear // code path through Duration.prototype.round that rounds to the nearest month: const expectedOpsForMonthRounding = expectedOpsForPlainRelativeTo.concat([ - // UnbalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 3.f - "call options.relativeTo.calendar.dateUntil", // 3.i + "call options.relativeTo.calendar.dateAdd", // 39.c + "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime // RoundDuration - "call options.relativeTo.calendar.dateAdd", // 13.c - "call options.relativeTo.calendar.dateAdd", // 13.e - "call options.relativeTo.calendar.dateUntil", // 13.m - "call options.relativeTo.calendar.dateAdd", // 13.q MoveRelativeDate - "call options.relativeTo.calendar.dateAdd", // 13.w MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 11.b + "call options.relativeTo.calendar.dateAdd", // 11.d + "call options.relativeTo.calendar.dateUntil", // 11.l + "call options.relativeTo.calendar.dateAdd", // 11.v MoveRelativeDate // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 10.d - "call options.relativeTo.calendar.dateUntil", // 10.e + "call options.relativeTo.calendar.dateAdd", // 9.d + "call options.relativeTo.calendar.dateUntil", // 9.e ]); const instance2 = new Temporal.Duration(1, 0, 0, 62); instance2.round(createOptionsObserver({ largestUnit: "months", smallestUnit: "months", relativeTo: plainRelativeTo })); @@ -169,24 +172,23 @@ actual.splice(0); // clear // code path through Duration.prototype.round that rounds to the nearest week: const expectedOpsForWeekRounding = expectedOpsForPlainRelativeTo.concat([ - // UnbalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 4.e + "call options.relativeTo.calendar.dateAdd", // 39.c + "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime // RoundDuration - "call options.relativeTo.calendar.dateUntil", // 14.f - "call options.relativeTo.calendar.dateAdd", // 14.j MoveRelativeDate - "call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate + "call options.relativeTo.calendar.dateUntil", // 12.e + "call options.relativeTo.calendar.dateAdd", // 12.o MoveRelativeDate // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 16 - "call options.relativeTo.calendar.dateUntil", // 17 + "call options.relativeTo.calendar.dateAdd", // 14 + "call options.relativeTo.calendar.dateUntil", // 15 ]); const instance3 = new Temporal.Duration(1, 1, 0, 15); instance3.round(createOptionsObserver({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo: plainRelativeTo })); assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with largestUnit = smallestUnit = weeks"); actual.splice(0); // clear -// code path through UnbalanceDurationRelative that rounds to the nearest day: +// code path through Duration.prototype.round that rounds to the nearest day: const expectedOpsForDayRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 9 + "call options.relativeTo.calendar.dateAdd", // 39.c ]); const instance4 = new Temporal.Duration(1, 1, 1) instance4.round(createOptionsObserver({ largestUnit: "days", smallestUnit: "days", relativeTo: plainRelativeTo })); @@ -195,8 +197,10 @@ actual.splice(0); // clear // code path through BalanceDateDurationRelative balancing from days up to years: const expectedOpsForDayToYearBalancing = expectedOpsForPlainRelativeTo.concat([ + "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateUntil", // 9.d + "call options.relativeTo.calendar.dateAdd", // 8.c + "call options.relativeTo.calendar.dateUntil", // 8.d ]); const instance5 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 396 * 24); instance5.round(createOptionsObserver({ largestUnit: "years", smallestUnit: "days", relativeTo: plainRelativeTo })); @@ -205,13 +209,15 @@ actual.splice(0); // clear // code path through Duration.prototype.round balancing from months up to years: const expectedOpsForMonthToYearBalancing = expectedOpsForPlainRelativeTo.concat([ + "call options.relativeTo.calendar.dateAdd", // 39.c + "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime // RoundDuration - "call options.relativeTo.calendar.dateAdd", // 13.c - "call options.relativeTo.calendar.dateAdd", // 13.e - "call options.relativeTo.calendar.dateAdd", // 13.w MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 11.b + "call options.relativeTo.calendar.dateAdd", // 11.d + "call options.relativeTo.calendar.dateAdd", // 11.v MoveRelativeDate // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 9.c - "call options.relativeTo.calendar.dateUntil", // 9.d + "call options.relativeTo.calendar.dateAdd", // 8.c + "call options.relativeTo.calendar.dateUntil", // 8.d ]); const instance6 = new Temporal.Duration(0, 12); instance6.round(createOptionsObserver({ largestUnit: "years", smallestUnit: "months", relativeTo: plainRelativeTo })); @@ -219,8 +225,10 @@ assert.compareArray(actual, expectedOpsForMonthToYearBalancing, "order of operat actual.splice(0); // clear const expectedOpsForDayToMonthBalancing = expectedOpsForPlainRelativeTo.concat([ + "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateUntil", // 10.e + "call options.relativeTo.calendar.dateAdd", // 9.d + "call options.relativeTo.calendar.dateUntil", // 9.e ]); const instance7 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 32 * 24); instance7.round(createOptionsObserver({ largestUnit: "months", smallestUnit: "days", relativeTo: plainRelativeTo })); @@ -228,8 +236,10 @@ assert.compareArray(actual, expectedOpsForDayToMonthBalancing, "order of operati actual.splice(0); // clear const expectedOpsForDayToWeekBalancing = expectedOpsForPlainRelativeTo.concat([ + "call options.relativeTo.calendar.dateUntil", // DifferencePlainDateTimeWithRounding → DifferenceISODateTime // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateUntil", // 17 + "call options.relativeTo.calendar.dateAdd", // 14 + "call options.relativeTo.calendar.dateUntil", // 15 ]); const instance8 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 8 * 24); instance8.round(createOptionsObserver({ largestUnit: "weeks", smallestUnit: "days", relativeTo: plainRelativeTo })); @@ -351,18 +361,18 @@ const expectedOpsForMinimalYearRoundingZoned = expectedOpsForZonedRelativeTo.con // lookup in Duration.p.round "get options.relativeTo.calendar.dateAdd", "get options.relativeTo.calendar.dateUntil", - // NanosecondsToDays - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 11. GetPlainDateTimeFor - // NanosecondsToDays → AddDaysToZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // NanosecondsToDays → AddDaysToZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", + // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c + "call options.relativeTo.calendar.dateUntil", // 13.f // RoundDuration - // 7.e and 7.g not called because years, months, weeks are 0 - "call options.relativeTo.calendar.dateUntil", // 7.o - // 7.s not called because years, months, weeks are 0 - "call options.relativeTo.calendar.dateAdd", // 7.y MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 7.a.i MoveRelativeZonedDateTime + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 7.a.i MoveRelativeZonedDateTime + // 10.b not called because years, months, weeks are 0 + "call options.relativeTo.calendar.dateAdd", // 10.d + "call options.relativeTo.calendar.dateUntil", // 10.l + // 10.p not called because years, months, weeks are 0 + "call options.relativeTo.calendar.dateAdd", // 10.v MoveRelativeDate ]); instance.round(createOptionsObserver({ smallestUnit: "years", relativeTo: zonedRelativeTo })); assert.compareArray( @@ -372,34 +382,30 @@ assert.compareArray( ); actual.splice(0); // clear -// code path through RoundDuration that rounds to the nearest year: +// code path through Duration.p.round that rounds to the nearest year: const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ // ToTemporalDate "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // lookup in Duration.p.round "get options.relativeTo.calendar.dateAdd", "get options.relativeTo.calendar.dateUntil", - // MoveRelativeZonedDateTime → AddZonedDateTime - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // NanosecondsToDays - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 8. GetPlainDateTimeFor - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 9. GetPlainDateTimeFor - // NanosecondsToDays → AddDaysToZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // NanosecondsToDays → AddDaysToZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.calendar.dateAdd", // 12.d - "call options.relativeTo.calendar.dateAdd", // 12.f - "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 + // AddZonedDateTime "call options.relativeTo.calendar.dateAdd", "call options.relativeTo.timeZone.getPossibleInstantsFor", + // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c + "call options.relativeTo.calendar.dateUntil", // 13.f + // RoundDuration + "call options.relativeTo.calendar.dateAdd", // 7.a.i MoveRelativeZonedDateTime + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 7.a.i MoveRelativeZonedDateTime + "call options.relativeTo.calendar.dateAdd", // 10.b + "call options.relativeTo.calendar.dateAdd", // 10.d + "call options.relativeTo.calendar.dateUntil", // 10.l + "call options.relativeTo.calendar.dateAdd", // 10.v MoveRelativeDate // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 9.c - "call options.relativeTo.calendar.dateUntil", // 9.d + "call options.relativeTo.calendar.dateAdd", // 8.c + "call options.relativeTo.calendar.dateUntil", // 8.d ]); instanceYears.round(createOptionsObserver({ smallestUnit: "years", relativeTo: zonedRelativeTo })); assert.compareArray( @@ -409,9 +415,8 @@ assert.compareArray( ); actual.splice(0); // clear -// code path that hits UnbalanceDateDurationRelative, RoundDuration, and -// BalanceDateDurationRelative -const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat([ +// code path that hits the special weeks/years case in BalanceDateDurationRelative +const expectedOpsForYearsWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([ // ToTemporalDate "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // lookup in Duration.p.round @@ -421,26 +426,31 @@ const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime "call options.relativeTo.calendar.dateAdd", "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor + // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c + "call options.relativeTo.calendar.dateUntil", // 13.f // RoundDuration - "call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate - // MoveRelativeZonedDateTime → AddZonedDateTime - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", + "call options.relativeTo.calendar.dateAdd", // 7.a.i MoveRelativeZonedDateTime + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 7.a.i MoveRelativeZonedDateTime + "call options.relativeTo.calendar.dateUntil", // 12.e + "call options.relativeTo.calendar.dateAdd", // 12.i MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 12.o MoveRelativeDate // BalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 10.d - "call options.relativeTo.calendar.dateUntil", // 10.e + "call options.relativeTo.calendar.dateAdd", // 8.a.iii + "call options.relativeTo.calendar.dateUntil", // 8.a.iv ]); new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "years", smallestUnit: "weeks", relativeTo: zonedRelativeTo })); assert.compareArray( actual, - expectedOpsForUnbalanceRoundBalance, + expectedOpsForYearsWeeksSpecialCase, "order of operations with largestUnit = years, smallestUnit = weeks, and ZonedDateTime relativeTo" ); actual.splice(0); // clear // code path that skips user code calls in BalanceDateDurationRelative due to // special case for largestUnit months and smallestUnit weeks -const expectedOpsForWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([ +const expectedOpsForMonthsWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([ // ToTemporalDate "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // lookup in Duration.p.round @@ -449,16 +459,21 @@ const expectedOpsForWeeksSpecialCase = expectedOpsForZonedRelativeTo.concat([ // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime "call options.relativeTo.calendar.dateAdd", "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor + // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c + "call options.relativeTo.calendar.dateUntil", // 13.f // RoundDuration - "call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate - // MoveRelativeZonedDateTime → AddZonedDateTime - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", + "call options.relativeTo.calendar.dateAdd", // 7.a.i MoveRelativeZonedDateTime + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 7.a.i MoveRelativeZonedDateTime + "call options.relativeTo.calendar.dateUntil", // 12.e + "call options.relativeTo.calendar.dateAdd", // 12.i MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 12.o MoveRelativeDate ]); new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "months", smallestUnit: "weeks", relativeTo: zonedRelativeTo })); assert.compareArray( actual, - expectedOpsForWeeksSpecialCase, + expectedOpsForMonthsWeeksSpecialCase, "order of operations with largestUnit = months, smallestUnit = weeks, and ZonedDateTime relativeTo" ); actual.splice(0); // clear 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 99ba61bb4b8..1ef0125cb28 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, 8, "getPossibleInstantsFor should have been called 8 times"); +assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-zoneddatetime-normalized-time-duration-to-days-range-errors.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-zoneddatetime-normalized-time-duration-to-days-range-errors.js index 32552a2608f..984de8bbaa3 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-zoneddatetime-normalized-time-duration-to-days-range-errors.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-zoneddatetime-normalized-time-duration-to-days-range-errors.js @@ -47,8 +47,9 @@ let zdt = new Temporal.ZonedDateTime( [[epochInstant]], // Returned in step 16, setting _relativeResult_ [ TemporalHelpers.SUBSTITUTE_SKIP, // Pre-conversion in Duration.p.round - dayNs - 1, // Returned in step 8, setting _startDateTime_ - -dayNs + 1, // Returned in step 9, setting _endDateTime_ + TemporalHelpers.SUBSTITUTE_SKIP, // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_ + -dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_ ] ) ); @@ -68,8 +69,9 @@ zdt = new Temporal.ZonedDateTime( [[epochInstant]], // Returned in step 16, setting _relativeResult_ [ TemporalHelpers.SUBSTITUTE_SKIP, // Pre-conversion in Duration.p.round - -dayNs + 1, // Returned in step 8, setting _startDateTime_ - dayNs - 1, // Returned in step 9, setting _endDateTime_ + TemporalHelpers.SUBSTITUTE_SKIP, // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + -dayNs + 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_ + dayNs - 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_ ] ) ); @@ -92,8 +94,9 @@ zdt = new Temporal.ZonedDateTime( ], [ TemporalHelpers.SUBSTITUTE_SKIP, // Pre-conversion in Duration.p.round - dayNs - 1, // Returned in step 8, setting _startDateTime_ - -dayNs + 1, // Returned in step 9, setting _endDateTime_ + TemporalHelpers.SUBSTITUTE_SKIP, // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_ + -dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_ ] ) ); diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-ceil.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-ceil.js index 27306ed1dfe..e12e1e442b0 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-ceil.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-ceil.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [6], [-5]], ["months", [5, 8], [-5, -7]], - ["weeks", [5, 6, 9], [-5, -6, -8]], + ["weeks", [5, 7, 4], [-5, -7, -3]], ["days", [5, 7, 0, 28], [-5, -7, 0, -27]], ["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -16]], ["minutes", [5, 7, 0, 27, 16, 31], [-5, -7, 0, -27, -16, -30]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js index 11196373494..65c336c1687 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [6], [-6]], ["months", [5, 8], [-5, -8]], - ["weeks", [5, 6, 9], [-5, -6, -9]], + ["weeks", [5, 7, 4], [-5, -7, -4]], ["days", [5, 7, 0, 28], [-5, -7, 0, -28]], ["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]], ["minutes", [5, 7, 0, 27, 16, 31], [-5, -7, 0, -27, -16, -31]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-floor.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-floor.js index 7e875cc95ce..aba4aada490 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-floor.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-floor.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [5], [-6]], ["months", [5, 7], [-5, -8]], - ["weeks", [5, 6, 8], [-5, -6, -9]], + ["weeks", [5, 7, 3], [-5, -7, -4]], ["days", [5, 7, 0, 27], [-5, -7, 0, -28]], ["hours", [5, 7, 0, 27, 16], [-5, -7, 0, -27, -17]], ["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -31]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.js index 556638410ce..f6902374646 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [6], [-6]], ["months", [5, 8], [-5, -8]], - ["weeks", [5, 6, 8], [-5, -6, -8]], + ["weeks", [5, 7, 4], [-5, -7, -4]], ["days", [5, 7, 0, 28], [-5, -7, 0, -28]], ["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]], ["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.js index 1facefa910c..289a20cb559 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [6], [-6]], ["months", [5, 8], [-5, -8]], - ["weeks", [5, 6, 8], [-5, -6, -8]], + ["weeks", [5, 7, 4], [-5, -7, -4]], ["days", [5, 7, 0, 28], [-5, -7, 0, -28]], ["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]], ["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfExpand.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfExpand.js index e5544b0e2b9..e62dc933ca1 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfExpand.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfExpand.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [6], [-6]], ["months", [5, 8], [-5, -8]], - ["weeks", [5, 6, 8], [-5, -6, -8]], + ["weeks", [5, 7, 4], [-5, -7, -4]], ["days", [5, 7, 0, 28], [-5, -7, 0, -28]], ["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]], ["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.js index 452893743f4..d38989e8f03 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [6], [-6]], ["months", [5, 8], [-5, -8]], - ["weeks", [5, 6, 8], [-5, -6, -8]], + ["weeks", [5, 7, 4], [-5, -7, -4]], ["days", [5, 7, 0, 28], [-5, -7, 0, -28]], ["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]], ["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.js index 2fa6a810b8a..c102efeea5d 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [6], [-6]], ["months", [5, 8], [-5, -8]], - ["weeks", [5, 6, 8], [-5, -6, -8]], + ["weeks", [5, 7, 4], [-5, -7, -4]], ["days", [5, 7, 0, 28], [-5, -7, 0, -28]], ["hours", [5, 7, 0, 27, 17], [-5, -7, 0, -27, -17]], ["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-trunc.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-trunc.js index ffe1beb00cf..817545903d9 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-trunc.js +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-trunc.js @@ -18,7 +18,7 @@ const relativeToBackwards = new Temporal.PlainDate(2020, 12, 1); const expected = [ ["years", [5], [-5]], ["months", [5, 7], [-5, -7]], - ["weeks", [5, 6, 8], [-5, -6, -8]], + ["weeks", [5, 7, 3], [-5, -7, -3]], ["days", [5, 7, 0, 27], [-5, -7, 0, -27]], ["hours", [5, 7, 0, 27, 16], [-5, -7, 0, -27, -16]], ["minutes", [5, 7, 0, 27, 16, 30], [-5, -7, 0, -27, -16, -30]], diff --git a/test/built-ins/Temporal/Duration/prototype/round/throws-in-unbalance-duration-relative-when-sign-mismatched.js b/test/built-ins/Temporal/Duration/prototype/round/throws-in-unbalance-duration-relative-when-sign-mismatched.js deleted file mode 100644 index 7e32ef0f491..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/round/throws-in-unbalance-duration-relative-when-sign-mismatched.js +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2022 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.round -description: > - UnbalanceDurationRelative throws a RangeError when duration signs don't match. -features: [Temporal] ----*/ - -var duration = Temporal.Duration.from({ - years: 1, - months: 0, - weeks: 1, -}); - -var cal = new class extends Temporal.Calendar { - called = 0; - dateUntil(one, two, options) { - ++this.called; - var result = super.dateUntil(one, two, options); - return this.called === 1 ? result.negated() : result; - } -}("iso8601"); - -var relativeTo = new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, 0, 0, 0, cal); -assert.sameValue(relativeTo.getCalendar(), cal); - -var options = { - smallestUnit: "days", - largestUnit: "month", - relativeTo, -}; - -assert.throws(RangeError, () => duration.round(options)); 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 26d685aba63..54b139c7685 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 @@ -34,9 +34,10 @@ features: [Temporal] const expected = [ "2000-01-01T00:00:00", // called once on the input relativeTo object + "2001-02-09T00:00:00", // called once adding the duration to relativeTo "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 + "2001-02-09T00:00:00", // called once in MoveRelativeZonedDateTime in RoundDuration + "2001-02-10T00:00:00", // called once in NormalizedTimeDurationToDays in RoundDuration ]; TemporalHelpers.checkTimeZonePossibleInstantsIterable((timeZone) => { diff --git a/test/built-ins/Temporal/Duration/prototype/total/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/Duration/prototype/total/calendar-dateadd-called-with-options-undefined.js index c4f048640c3..f731cf01ee1 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/calendar-dateadd-called-with-options-undefined.js +++ b/test/built-ins/Temporal/Duration/prototype/total/calendar-dateadd-called-with-options-undefined.js @@ -17,7 +17,7 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar); // Total of a calendar unit where larger calendar units have to be converted // down, to cover the path that goes through UnbalanceDateDurationRelative // The calls come from the path: -// Duration.total() -> UnbalanceDateDurationRelative -> calendar.dateAdd() +// Duration.total() -> AddZonedDateTime -> calendar.dateAdd() const instance1 = new Temporal.Duration(1, 1, 1, 1, 1); instance1.total({ unit: "days", relativeTo }); @@ -27,14 +27,15 @@ assert.sameValue(calendar.dateAddCallCount, 1, "converting larger calendar units // up, to cover the path that goes through MoveRelativeZonedDateTime // The calls come from these paths: // Duration.total() -> -// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() -// BalanceDuration -> -// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() -// RoundDuration -> -// MoveRelativeDate -> calendar.dateAdd() +// AddZonedDateTime -> calendar.dateAdd() +// DifferenceZonedDateTimeWithRounding -> +// RoundDuration -> +// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd() +// MoveRelativeDate -> calendar.dateAdd() +// BalanceDateDurationRelative -> calendar.dateAdd() calendar.dateAddCallCount = 0; const instance2 = new Temporal.Duration(0, 0, 1, 1); instance2.total({ unit: "weeks", relativeTo }); -assert.sameValue(calendar.dateAddCallCount, 3, "converting smaller calendar units up"); +assert.sameValue(calendar.dateAddCallCount, 4, "converting smaller calendar units up"); diff --git a/test/built-ins/Temporal/Duration/prototype/total/calendar-dateuntil-called-with-singular-largestunit.js b/test/built-ins/Temporal/Duration/prototype/total/calendar-dateuntil-called-with-singular-largestunit.js index d7f0a65ad34..144f72b9f17 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/calendar-dateuntil-called-with-singular-largestunit.js +++ b/test/built-ins/Temporal/Duration/prototype/total/calendar-dateuntil-called-with-singular-largestunit.js @@ -51,9 +51,9 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular( duration.total({ unit, relativeTo }); }, { - years: ["year"], - months: ["month"], - weeks: ["week"], + years: ["year", "year"], + months: ["month", "month", "month"], + weeks: ["week", "week", "week"], days: [], hours: [], minutes: [], diff --git a/test/built-ins/Temporal/Duration/prototype/total/dateuntil-field.js b/test/built-ins/Temporal/Duration/prototype/total/dateuntil-field.js index 1e20152bbfe..862e996180c 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/dateuntil-field.js +++ b/test/built-ins/Temporal/Duration/prototype/total/dateuntil-field.js @@ -26,6 +26,7 @@ const relativeTo = new Temporal.PlainDate(2018, 10, 12, calendar); const expected = [ "call dateUntil", + "call dateUntil", ]; const years = new Temporal.Duration(2); diff --git a/test/built-ins/Temporal/Duration/prototype/total/normalized-time-duration-to-days-loop-arbitrarily.js b/test/built-ins/Temporal/Duration/prototype/total/normalized-time-duration-to-days-loop-arbitrarily.js index 4e61345b596..eae892c33b8 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/normalized-time-duration-to-days-loop-arbitrarily.js +++ b/test/built-ins/Temporal/Duration/prototype/total/normalized-time-duration-to-days-loop-arbitrarily.js @@ -19,7 +19,7 @@ info: | features: [Temporal] ---*/ -const duration = Temporal.Duration.from({ days: 1 }); +const duration = new Temporal.Duration(0, 0, 1, 1, 1); const dayLengthNs = 86400000000000n; const dayInstant = new Temporal.Instant(dayLengthNs); @@ -34,10 +34,13 @@ const timeZone = new class extends Temporal.TimeZone { const relativeTo = new Temporal.ZonedDateTime(0n, timeZone); assert.throws(RangeError, () => duration.total({ unit: "days", relativeTo }), "indefinite loop is prevented"); -assert.sameValue(calls, 4, "getPossibleInstantsFor is not called indefinitely"); +assert.sameValue(calls, 5, "getPossibleInstantsFor is not called indefinitely"); // Expected calls: // AddZonedDateTime (1) - // NormalizedTimeDurationToDays -> - // AddDaysToZonedDateTime (2, step 12) - // AddDaysToZonedDateTime (3, step 15) - // AddDaysToZonedDateTime (4, step 18.d) + // DifferenceZonedDateTimeWithRounding -> + // DifferenceZonedDateTime -> GetInstantFor (2) + // RoundDuration -> + // MoveRelativeZonedDateTime -> AddZonedDateTime (3) + // NormalizedTimeDurationToDays -> + // AddDaysToZonedDateTime (5, step 18) + // AddDaysToZonedDateTime (6, step 21.d) diff --git a/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js b/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js index cafaaae372f..b47d45a1ea4 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js @@ -105,22 +105,32 @@ actual.splice(0); // clear // code path through RoundDuration that rounds to the nearest year with minimal calendar calls: const expectedOpsForMinimalYearRounding = expectedOpsForPlainRelativeTo.concat([ - // 12.d and 12.f not called because years, months, weeks are 0 - "call options.relativeTo.calendar.dateUntil", // 12.n - // 12.r not called because years, months, weeks are 0 - "call options.relativeTo.calendar.dateAdd", // 12.x MoveRelativeDate + // DifferencePlainDateTimeWithRounding -> DifferenceISODateTime + "call options.relativeTo.calendar.dateUntil", + // RoundDuration + // 10.b not called because years, months, weeks are 0 + "call options.relativeTo.calendar.dateAdd", // 10.d + "call options.relativeTo.calendar.dateUntil", // 10.l + // 10.p not called because years = 0 + "call options.relativeTo.calendar.dateAdd", // 10.v ]); instance.total(createOptionsObserver({ unit: "years", relativeTo: plainRelativeTo })); assert.compareArray(actual, expectedOpsForMinimalYearRounding, "order of operations with years = 0 and unit = years"); actual.splice(0); // clear -// code path through RoundDuration that rounds to the nearest year: +// code path through Duration.p.total that rounds to the nearest year: const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([ - "call options.relativeTo.calendar.dateAdd", // 12.d - "call options.relativeTo.calendar.dateAdd", // 12.f - "call options.relativeTo.calendar.dateUntil", // 12.n - "call options.relativeTo.calendar.dateAdd", // 12.r MoveRelativeDate - "call options.relativeTo.calendar.dateAdd", // 12.x MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // Duration.p.total 19.c + // DifferencePlainDateTimeWithRounding + "call options.relativeTo.calendar.dateUntil", // 5 + // RoundDuration + "call options.relativeTo.calendar.dateAdd", // 10.b + "call options.relativeTo.calendar.dateAdd", // 10.d + "call options.relativeTo.calendar.dateUntil", // 10.l + "call options.relativeTo.calendar.dateAdd", // 10.v + // BalanceDateDurationRelative + "call options.relativeTo.calendar.dateAdd", // 8.c + "call options.relativeTo.calendar.dateUntil", // 8.d ]); const instanceYears = new Temporal.Duration(1, 12, 0, 0, /* hours = */ 2400); instanceYears.total(createOptionsObserver({ unit: "years", relativeTo: plainRelativeTo })); @@ -129,15 +139,17 @@ actual.splice(0); // clear // code path through Duration.prototype.total that rounds to the nearest month: const expectedOpsForMonthRounding = expectedOpsForPlainRelativeTo.concat([ - // UnbalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 3.f - "call options.relativeTo.calendar.dateUntil", // 3.i + "call options.relativeTo.calendar.dateAdd", // Duration.p.total 19.c + // DifferencePlainDateTimeWithRounding + "call options.relativeTo.calendar.dateUntil", // 5 // RoundDuration - "call options.relativeTo.calendar.dateAdd", // 13.c - "call options.relativeTo.calendar.dateAdd", // 13.e - "call options.relativeTo.calendar.dateUntil", // 13.m - "call options.relativeTo.calendar.dateAdd", // 13.q MoveRelativeDate - "call options.relativeTo.calendar.dateAdd", // 13.w MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 11.b + "call options.relativeTo.calendar.dateAdd", // 11.d + "call options.relativeTo.calendar.dateUntil", // 11.l + "call options.relativeTo.calendar.dateAdd", // 11.v MoveRelativeDate + // BalanceDateDurationRelative + "call options.relativeTo.calendar.dateAdd", // 9.d + "call options.relativeTo.calendar.dateUntil", // 9.e ]); const instance2 = new Temporal.Duration(1, 0, 0, 62); instance2.total(createOptionsObserver({ unit: "months", relativeTo: plainRelativeTo })); @@ -146,12 +158,15 @@ actual.splice(0); // clear // code path through Duration.prototype.total that rounds to the nearest week: const expectedOpsForWeekRounding = expectedOpsForPlainRelativeTo.concat([ - // UnbalanceDateDurationRelative - "call options.relativeTo.calendar.dateAdd", // 4.e + "call options.relativeTo.calendar.dateAdd", // Duration.p.total 19.c + // DifferencePlainDateTimeWithRounding + "call options.relativeTo.calendar.dateUntil", // 5 // RoundDuration - "call options.relativeTo.calendar.dateUntil", // 14.f - "call options.relativeTo.calendar.dateAdd", // 14.j MoveRelativeDate - "call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate + "call options.relativeTo.calendar.dateUntil", // 12.e + "call options.relativeTo.calendar.dateAdd", // 12.o MoveRelativeDate + // BalanceDateDurationRelative + "call options.relativeTo.calendar.dateAdd", // 14 + "call options.relativeTo.calendar.dateUntil", // 15 ]); const instance3 = new Temporal.Duration(1, 1, 0, 15); instance3.total(createOptionsObserver({ unit: "weeks", relativeTo: plainRelativeTo })); @@ -268,28 +283,27 @@ assert.compareArray(actual, expectedOpsForZonedRelativeTo.concat([ ]), "order of operations for ZonedDateTime relativeTo"); actual.splice(0); // clear -// code path through RoundDuration that rounds to the nearest year with minimal calendar operations: +// code path through Duration.p.total that rounds to the nearest year with +// minimal calendar operations: const expectedOpsForMinimalYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ // ToTemporalDate "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // lookup in Duration.p.total "get options.relativeTo.calendar.dateAdd", "get options.relativeTo.calendar.dateUntil", - // BalancePossiblyInfiniteDuration → NanosecondsToDays - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 11. GetPlainDateTimeFor - // BalancePossiblyInfiniteDuration → NanosecondsToDays → AddDaysToZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // BalancePossiblyInfiniteDuration → NanosecondsToDays → AddDaysToZonedDateTime + // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c + "call options.relativeTo.calendar.dateUntil", // 13.f + // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime + "call options.relativeTo.calendar.dateAdd", "call options.relativeTo.timeZone.getPossibleInstantsFor", -], [ // code path through RoundDuration that rounds to the nearest year: - // MoveRelativeZonedDateTime → AddDaysToZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // 12.d and 12.f not called because years, months, weeks are 0 - "call options.relativeTo.calendar.dateUntil", // 12.n - // 12.r not called because years, months, weeks are 0 - "call options.relativeTo.calendar.dateAdd", // 12.x MoveRelativeDate + // 10.b not called because years, months, weeks are 0 + "call options.relativeTo.calendar.dateAdd", // 10.d + "call options.relativeTo.calendar.dateUntil", // 10.l + // 10.p not called because years = 0 + "call options.relativeTo.calendar.dateAdd", // 10.v MoveRelativeDate ]); instance.total(createOptionsObserver({ unit: "years", relativeTo: zonedRelativeTo })); assert.compareArray( @@ -299,32 +313,31 @@ assert.compareArray( ); actual.splice(0); // clear -// code path through RoundDuration that rounds to the nearest year: +// code path through Duration.p.total that rounds to years: const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ // ToTemporalDate "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // lookup in Duration.p.total "get options.relativeTo.calendar.dateAdd", "get options.relativeTo.calendar.dateUntil", - // MoveRelativeZonedDateTime → AddZonedDateTime + // 18.c AddZonedDateTime "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // BalancePossiblyInfiniteTimeDurationRelative → NanosecondsToDays - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 8. GetPlainDateTimeFor - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 9. GetPlainDateTimeFor - // BalancePossiblyInfiniteTimeDurationRelative → NanosecondsToDays → AddDaysToZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // BalancePossiblyInfiniteTimeDurationRelative → NanosecondsToDays → AddDaysToZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor + // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c + "call options.relativeTo.calendar.dateUntil", // 13.f // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime "call options.relativeTo.calendar.dateAdd", "call options.relativeTo.timeZone.getPossibleInstantsFor", // RoundDuration - "call options.relativeTo.calendar.dateAdd", // 12.d - "call options.relativeTo.calendar.dateAdd", // 12.f - "call options.relativeTo.calendar.dateUntil", // 12.n - "call options.relativeTo.calendar.dateAdd", // 12.r MoveRelativeDate - "call options.relativeTo.calendar.dateAdd", // 12.x MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 10.b + "call options.relativeTo.calendar.dateAdd", // 10.d + "call options.relativeTo.calendar.dateUntil", // 10.l + "call options.relativeTo.calendar.dateAdd", // 10.v MoveRelativeDate + // BalanceDateDurationRelative + "call options.relativeTo.calendar.dateAdd", // 8.c + "call options.relativeTo.calendar.dateUntil", // 8.d ]); instanceYears.total(createOptionsObserver({ unit: "years", relativeTo: zonedRelativeTo })); assert.compareArray( @@ -334,60 +347,67 @@ assert.compareArray( ); actual.splice(0); // clear -// code path that hits UnbalanceDateDurationRelative and RoundDuration -const expectedOpsForUnbalanceRound = expectedOpsForZonedRelativeTo.concat([ +// code path through Duration.p.total that rounds to months: +const expectedOpsForMonthsRoundingZoned = expectedOpsForZonedRelativeTo.concat([ // ToTemporalDate "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // lookup in Duration.p.total "get options.relativeTo.calendar.dateAdd", "get options.relativeTo.calendar.dateUntil", - // No user code calls in UnbalanceDateDurationRelative - // MoveRelativeZonedDateTime → AddZonedDateTime + // 18.c AddZonedDateTime "call options.relativeTo.calendar.dateAdd", "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor + // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c + "call options.relativeTo.calendar.dateUntil", // 13.f // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime "call options.relativeTo.calendar.dateAdd", "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor // RoundDuration - "call options.relativeTo.calendar.dateAdd", // 13.c - "call options.relativeTo.calendar.dateAdd", // 13.e - "call options.relativeTo.calendar.dateUntil", // 13.m - "call options.relativeTo.calendar.dateAdd", // 13.w MoveRelativeDate + "call options.relativeTo.calendar.dateAdd", // 11.b + "call options.relativeTo.calendar.dateAdd", // 11.d + "call options.relativeTo.calendar.dateUntil", // 11.l + "call options.relativeTo.calendar.dateAdd", // 11.v MoveRelativeDate + // BalanceDateDurationRelative + "call options.relativeTo.calendar.dateAdd", // 9.d + "call options.relativeTo.calendar.dateUntil", // 9.e ]); new Temporal.Duration(0, 1, 1).total(createOptionsObserver({ unit: "months", relativeTo: zonedRelativeTo })); assert.compareArray( actual, - expectedOpsForUnbalanceRound, + expectedOpsForMonthsRoundingZoned, "order of operations with unit = months and ZonedDateTime relativeTo" ); actual.splice(0); // clear -// code path that avoids converting Zoned twice in BalanceTimeDurationRelative -const expectedOpsForBalanceRound = expectedOpsForZonedRelativeTo.concat([ +// code path through Duration.p.total that rounds to weeks: +const expectedOpsForWeeksRoundingZoned = expectedOpsForZonedRelativeTo.concat([ // ToTemporalDate "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // lookup in Duration.p.total "get options.relativeTo.calendar.dateAdd", "get options.relativeTo.calendar.dateUntil", - // No user code calls in UnbalanceDateDurationRelative - // No user code calls in AddZonedDateTime (years, months, weeks = 0) - // BalanceTimeDurationRelative - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 4.a - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 4.b - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // NanosecondsToDays 9 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // NanosecondsToDays 26 - "call options.relativeTo.timeZone.getPossibleInstantsFor", // NanosecondsToDays 31.a + // 18.c AddZonedDateTime + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor + // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime + "call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5 + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 12.c + "call options.relativeTo.calendar.dateUntil", // 13.f // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime - "call options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor + "call options.relativeTo.calendar.dateAdd", + "call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor // RoundDuration - "call options.relativeTo.calendar.dateUntil", // 14.f - "call options.relativeTo.calendar.dateAdd", // 14.j MoveRelativeDate - "call options.relativeTo.calendar.dateAdd", // 14.p MoveRelativeDate + "call options.relativeTo.calendar.dateUntil", // 12.e + "call options.relativeTo.calendar.dateAdd", // 12.o MoveRelativeDate + // BalanceDateDurationRelative + "call options.relativeTo.calendar.dateAdd", // 14 + "call options.relativeTo.calendar.dateUntil", // 15 ]); new Temporal.Duration(0, 0, 0, 1, 240).total(createOptionsObserver({ unit: "weeks", relativeTo: zonedRelativeTo })); assert.compareArray( actual, - expectedOpsForBalanceRound, + expectedOpsForWeeksRoundingZoned, "order of operations with unit = weeks and no calendar units" ); actual.splice(0); // clear diff --git a/test/built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-3.js b/test/built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-3.js index 0e0bb8b9613..fdca23c28ab 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-3.js +++ b/test/built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-3.js @@ -25,7 +25,7 @@ info: | 12. If _unit_ is *"week"*, then ... s. Let _fractionalWeeks_ be _weeks_ + _fractionalDays_ / abs(_oneWeekDays_). -includes: [compareArray.js] +includes: [compareArray.js, temporalHelpers.js] features: [Temporal] ---*/ @@ -68,24 +68,32 @@ function f64Repr(f) { // ============ -const tz = new (class extends Temporal.TimeZone { - getPossibleInstantsFor() { +function createTimeZone() { + const tz = new Temporal.TimeZone("UTC"); + TemporalHelpers.substituteMethod(tz, "getPossibleInstantsFor", [ + TemporalHelpers.SUBSTITUTE_SKIP, // Called in NormalizedTimeDurationToDays 19 from RoundDuration 7.b. // Sets _result_.[[DayLength]] to 2⁵³ - 1 ns, its largest possible value - return [new Temporal.Instant(-86400_0000_0000_000_000_000n + 2n ** 53n - 1n)]; - } -})("UTC"); + [new Temporal.Instant(-86400_0000_0000_000_000_000n + 2n ** 53n - 1n)], + ]); + return tz; +} -const cal = new (class extends Temporal.Calendar { - dateAdd() { +function createCalendar() { + const cal = new Temporal.Calendar("iso8601"); + TemporalHelpers.substituteMethod(cal, "dateAdd", [ // Called in MoveRelativeDate from RoundDuration 10.x, 11.x, or 12.q. // Sets _oneYearDays_, _oneMonthDays_, or _oneWeekDays_ respectively to // 200_000_000, its largest possible value. - return new Temporal.PlainDate(275760, 9, 13); - } -})("iso8601"); + new Temporal.PlainDate(275760, 9, 13), + ]); + return cal; +} + +function createRelativeTo() { + return new Temporal.ZonedDateTime(-86400_0000_0000_000_000_000n, createTimeZone(), createCalendar()); +} -const relativeTo = new Temporal.ZonedDateTime(-86400_0000_0000_000_000_000n, tz, cal); const d = new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, /* nanoseconds = */ 1); /* @@ -113,6 +121,6 @@ assert.sameValue(nextDown(expected), 5.55111512312578_281826e-25, "the next Numb // The next Number in direction +Infinity is less precise. assert.sameValue(nextUp(expected), 5.55111512312578_465497e-25, "the next Number in direction +Infinity is less precise"); -assert.sameValue(d.total({ unit: "years", relativeTo }), expected, "Correct division by large number in years total"); -assert.sameValue(d.total({ unit: "months", relativeTo }), expected, "Correct division by large number in months total"); -assert.sameValue(d.total({ unit: "weeks", relativeTo }), expected, "Correct division by large number in weeks total"); +assert.sameValue(d.total({ unit: "years", relativeTo: createRelativeTo() }), expected, "Correct division by large number in years total"); +assert.sameValue(d.total({ unit: "months", relativeTo: createRelativeTo() }), expected, "Correct division by large number in months total"); +assert.sameValue(d.total({ unit: "weeks", relativeTo: createRelativeTo() }), expected, "Correct division by large number in weeks total"); diff --git a/test/built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-4.js b/test/built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-4.js index 7514ac98536..dd893784996 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-4.js +++ b/test/built-ins/Temporal/Duration/prototype/total/precision-exact-mathematical-values-4.js @@ -73,12 +73,10 @@ function f64Repr(f) { function createTimeZone() { const tz = new Temporal.TimeZone("UTC"); TemporalHelpers.substituteMethod(tz, "getPossibleInstantsFor", [ - TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 19.a MoveRelativeZonedDateTime → AddZonedDateTime - TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 19.e.ii AddDaysToZonedDateTime - TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 19.i.ii NormalizedTimeDurationToDays step 16 - TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 19.i.ii NormalizedTimeDurationToDays step 19 + TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 18.c AddZonedDateTime + TemporalHelpers.SUBSTITUTE_SKIP, // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime → AddZonedDateTime [new Temporal.Instant(-86400_0000_0000_000_000_000n)], // RoundDuration step 7.a.i MoveRelativeZonedDateTime → AddZonedDateTime - [new Temporal.Instant(-86400_0000_0000_000_000_000n + 2n ** 53n - 1n)], // RoundDuration step 7.a.ii NormalizedTimeDurationToDays step 19 + [new Temporal.Instant(-86400_0000_0000_000_000_000n + 2n ** 53n - 1n)], // RoundDuration step 7.a.ii NormalizedTimeDurationToDays step 18 // sets dayLengthNs to Number.MAX_SAFE_INTEGER ]); return tz; @@ -87,7 +85,7 @@ function createTimeZone() { function createCalendar() { const cal = new Temporal.Calendar("iso8601"); TemporalHelpers.substituteMethod(cal, "dateAdd", [ - TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 19.a MoveRelativeZonedDateTime → AddZonedDateTime + TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 18.c AddZonedDateTime TemporalHelpers.SUBSTITUTE_SKIP, // RoundDuration step 7.a.i MoveRelativeZonedDateTime → AddZonedDateTime new Temporal.PlainDate(-271821, 4, 20), // RoundDuration step 10.d/11.d AddDate new Temporal.PlainDate(-271821, 4, 20), // RoundDuration step 10.f/11.f AddDate @@ -142,11 +140,11 @@ assert.sameValue(dMonths.total({ unit: "months", relativeTo }), expected, "Corre // Weeks calculation doesn't have the AddDate calls to convert months/weeks to days const weeksCal = new Temporal.Calendar("iso8601"); TemporalHelpers.substituteMethod(weeksCal, "dateAdd", [ - TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 19.a MoveRelativeZonedDateTime → AddZonedDateTime + TemporalHelpers.SUBSTITUTE_SKIP, // Duration.total step 18.c AddZonedDateTime TemporalHelpers.SUBSTITUTE_SKIP, // RoundDuration step 7.a.i MoveRelativeZonedDateTime → AddZonedDateTime new Temporal.PlainDate(275760, 9, 13), // RoundDuration step 12.q MoveRelativeDate // sets one{Year,Month,Week}Days to 200_000_000 ]); relativeTo = new Temporal.ZonedDateTime(-86400_0000_0000_000_000_000n, createTimeZone(), weeksCal); -const dWeeks = new Temporal.Duration(0, 0, /* weejs = */ 1, /* days = */ 1, 0, 0, 0, /* milliseconds = */ 199, 0, /* nanoseconds = */ 1); +const dWeeks = new Temporal.Duration(0, 0, /* weeks = */ 1, /* days = */ 1, 0, 0, 0, /* milliseconds = */ 199, 0, /* nanoseconds = */ 1); assert.sameValue(dWeeks.total({ unit: "weeks", relativeTo }), expected, "Correct division by large number in weeks total"); diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js index a5205f6ab76..d168646d1ed 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js +++ b/test/built-ins/Temporal/Duration/prototype/total/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.total({ unit: "days", relativeTo }); -assert.sameValue(timeZone.calls, 10, "getPossibleInstantsFor should have been called 10 times"); +assert.sameValue(timeZone.calls, 8, "getPossibleInstantsFor should have been called 8 times"); diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-normalized-time-duration-to-days-range-errors.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-normalized-time-duration-to-days-range-errors.js index 20e696f3409..5f3c21e5f67 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-normalized-time-duration-to-days-range-errors.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-zoneddatetime-normalized-time-duration-to-days-range-errors.js @@ -47,6 +47,7 @@ let zdt = new Temporal.ZonedDateTime( [[epochInstant]], // Returned in step 16, setting _relativeResult_ [ TemporalHelpers.SUBSTITUTE_SKIP, // Pre-conversion in Duration.p.total + TemporalHelpers.SUBSTITUTE_SKIP, // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime dayNs - 1, // Returned in step 8, setting _startDateTime_ -dayNs + 1, // Returned in step 9, setting _endDateTime_ ] @@ -68,6 +69,7 @@ zdt = new Temporal.ZonedDateTime( [[epochInstant]], // Returned in step 16, setting _relativeResult_ [ TemporalHelpers.SUBSTITUTE_SKIP, // Pre-conversion in Duration.p.total + TemporalHelpers.SUBSTITUTE_SKIP, // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime -dayNs + 1, // Returned in step 8, setting _startDateTime_ dayNs - 1, // Returned in step 9, setting _endDateTime_ ] @@ -92,6 +94,7 @@ zdt = new Temporal.ZonedDateTime( ], [ TemporalHelpers.SUBSTITUTE_SKIP, // pre-conversion in Duration.p.total + TemporalHelpers.SUBSTITUTE_SKIP, // DifferenceZonedDateTimeWithRounding → DifferenceZonedDateTime dayNs - 1, // Returned in step 8, setting _startDateTime_ -dayNs + 1, // Returned in step 9, setting _endDateTime_ ] diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js index e8ecae39bc4..a95a1afd18a 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-loop-arbitrarily.js @@ -32,12 +32,14 @@ const timeZone = new class extends Temporal.TimeZone { const zdt = new Temporal.ZonedDateTime(0n, timeZone); const other = new Temporal.ZonedDateTime(dayLengthNs * 2n, "UTC", "iso8601"); -assert.throws(RangeError, () => zdt.since(other, { largestUnit: "day", smallestUnit: "second" }), "indefinite loop is prevented"); -assert.sameValue(calls, 4, "getPossibleInstantsFor is not called indefinitely"); +assert.throws(RangeError, () => zdt.since(other, { smallestUnit: "days" }), "indefinite loop is prevented"); +assert.sameValue(calls, 5, "getPossibleInstantsFor is not called indefinitely"); // Expected calls: - // DifferenceTemporalZonedDateTime -> - // DifferenceZonedDateTime -> GetInstantFor (1) + // DifferenceTemporalZonedDateTime -> DifferenceZonedDateTimeWithRounding -> + // DifferenceZonedDateTime -> GetInstantFor (1) + // RoundDuration -> + // MoveRelativeZonedDateTime -> AddZonedDateTime -> AddDaysToZonedDateTime (2) // NormalizedTimeDurationToDays -> - // AddDaysToZonedDateTime (2, step 12) - // AddDaysToZonedDateTime (3, step 15) - // AddDaysToZonedDateTime (4, step 18.d) + // AddDaysToZonedDateTime (3, step 12) + // AddDaysToZonedDateTime (4, step 15) + // AddDaysToZonedDateTime (5, step 18.d) diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-range-errors.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-range-errors.js index 997e060c595..990d846113d 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-range-errors.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/normalized-time-duration-to-days-range-errors.js @@ -39,7 +39,7 @@ const dayNs = 86_400_000_000_000; const zeroZDT = new Temporal.ZonedDateTime(0n, "UTC"); const oneZDT = new Temporal.ZonedDateTime(1n, "UTC"); const epochInstant = new Temporal.Instant(0n); -const options = { largestUnit: "days", smallestUnit: "seconds", roundingMode: "expand" }; +const options = { smallestUnit: "days", roundingMode: "expand" }; // Step 23: days < 0 and sign = 1 let start = new Temporal.ZonedDateTime( diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/normalized-time-duration-to-days-loop-arbitrarily.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/normalized-time-duration-to-days-loop-arbitrarily.js index 5f38d19ed49..4148452b685 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/normalized-time-duration-to-days-loop-arbitrarily.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/normalized-time-duration-to-days-loop-arbitrarily.js @@ -32,12 +32,14 @@ const timeZone = new class extends Temporal.TimeZone { const zdt = new Temporal.ZonedDateTime(0n, timeZone); const other = new Temporal.ZonedDateTime(dayLengthNs * 2n, "UTC", "iso8601"); -assert.throws(RangeError, () => zdt.until(other, { largestUnit: "day", smallestUnit: "second" }), "indefinite loop is prevented"); -assert.sameValue(calls, 4, "getPossibleInstantsFor is not called indefinitely"); +assert.throws(RangeError, () => zdt.until(other, { smallestUnit: "days" }), "indefinite loop is prevented"); +assert.sameValue(calls, 5, "getPossibleInstantsFor is not called indefinitely"); // Expected calls: - // DifferenceTemporalZonedDateTime -> - // DifferenceZonedDateTime -> GetInstantFor (1) + // DifferenceTemporalZonedDateTime -> DifferenceZonedDateTimeWithRounding -> + // DifferenceZonedDateTime -> GetInstantFor (1) + // RoundDuration -> + // MoveRelativeZonedDateTime -> AddZonedDateTime -> AddDaysToZonedDateTime (2) // NormalizedTimeDurationToDays -> - // AddDaysToZonedDateTime (2, step 12) - // AddDaysToZonedDateTime (3, step 15) - // AddDaysToZonedDateTime (4, step 18.d) + // AddDaysToZonedDateTime (3, step 12) + // AddDaysToZonedDateTime (4, step 15) + // AddDaysToZonedDateTime (5, step 18.d) diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/normalized-time-duration-to-days-range-errors.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/normalized-time-duration-to-days-range-errors.js index ea2ebabe430..811243daeb5 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/normalized-time-duration-to-days-range-errors.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/normalized-time-duration-to-days-range-errors.js @@ -39,7 +39,7 @@ const dayNs = 86_400_000_000_000; const zeroZDT = new Temporal.ZonedDateTime(0n, "UTC"); const oneZDT = new Temporal.ZonedDateTime(1n, "UTC"); const epochInstant = new Temporal.Instant(0n); -const options = { largestUnit: "days", smallestUnit: "seconds", roundingMode: "expand" }; +const options = { smallestUnit: "days", roundingMode: "expand" }; // Step 23: days < 0 and sign = 1 let start = new Temporal.ZonedDateTime( diff --git a/test/staging/Temporal/Duration/old/round.js b/test/staging/Temporal/Duration/old/round.js index 5bc92fb56a5..2a4c379f84c 100644 --- a/test/staging/Temporal/Duration/old/round.js +++ b/test/staging/Temporal/Duration/old/round.js @@ -324,7 +324,7 @@ var roundAndBalanceResults = { years: { years: "P6Y", months: "P5Y6M", - weeks: "P5Y5M6W", + weeks: "P5Y6M1W", days: "P5Y6M10D", hours: "P5Y6M10DT5H", minutes: "P5Y6M10DT5H5M", @@ -335,7 +335,7 @@ var roundAndBalanceResults = { }, months: { months: "P66M", - weeks: "P65M6W", + weeks: "P66M1W", days: "P66M10D", hours: "P66M10DT5H", minutes: "P66M10DT5H5M",