Adjustments to tests for added invocations of BalanceDurationRelative

In order to fix tc39/proposal-temporal#2563, we added invocations of
BalanceDurationRelative after some invocations of RoundDuration. These
cause observable calendar calls, which must be accounted for in some
existing tests.
This commit is contained in:
Philip Chimento 2023-05-03 12:21:56 -07:00 committed by Philip Chimento
parent 93304c7571
commit 7c41695f78
14 changed files with 182 additions and 38 deletions

View File

@ -136,7 +136,13 @@ const expectedOpsForYearRounding = expected.concat([
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateUntil", // 7.o
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.s not called because other units can't add up to >1 year at this point)
// (7.s not called because other units can't add up to >1 year at this point)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
@ -159,7 +165,13 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.o not called because months and weeks == 0)
// (7.o not called because months and weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.since(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
actual.splice(0); // clear
@ -175,7 +187,10 @@ const expectedOpsForMonthRounding = expected.concat([
"call this.calendar.dateAdd", // 10.c
"call this.calendar.dateAdd", // 10.e
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
]); // (10.n.iii MoveRelativeDate not called because weeks == 0)
// (10.n.iii MoveRelativeDate not called because weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
]);
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
actual.splice(0); // clear
@ -189,6 +204,9 @@ const expectedOpsForWeekRounding = expected.concat([
"call this.calendar.dateUntil",
// RoundDuration
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
]); // (11.g.iii MoveRelativeDate not called because days already balanced)
// (11.g.iii MoveRelativeDate not called because days already balanced)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
]);
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");

View File

@ -137,7 +137,13 @@ const expectedOpsForYearRounding = expected.concat([
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateUntil", // 7.o
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.s not called because other units can't add up to >1 year at this point)
// (7.s not called because other units can't add up to >1 year at this point)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
@ -160,7 +166,13 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.o not called because months and weeks == 0)
// (7.o not called because months and weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
actual.splice(0); // clear
@ -176,7 +188,10 @@ const expectedOpsForMonthRounding = expected.concat([
"call this.calendar.dateAdd", // 10.c
"call this.calendar.dateAdd", // 10.e
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
]); // (10.n.iii MoveRelativeDate not called because weeks == 0)
// (10.n.iii MoveRelativeDate not called because weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
]);
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
actual.splice(0); // clear
@ -190,6 +205,9 @@ const expectedOpsForWeekRounding = expected.concat([
"call this.calendar.dateUntil",
// RoundDuration
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
]); // (11.g.iii MoveRelativeDate not called because days already balanced)
// (11.g.iii MoveRelativeDate not called because days already balanced)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
]);
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");

View File

@ -166,7 +166,13 @@ const expectedOpsForYearRounding = expected.concat([
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateUntil", // 7.o
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.s not called because other units can't add up to >1 year at this point)
// (7.s not called because other units can't add up to >1 year at this point)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
@ -195,7 +201,13 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.o not called because months and weeks == 0)
// (7.o not called because months and weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
actual.splice(0); // clear
@ -211,7 +223,10 @@ const expectedOpsForMonthRounding = expected.concat([
"call this.calendar.dateAdd", // 10.c
"call this.calendar.dateAdd", // 10.e
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
]); // (10.n.iii MoveRelativeDate not called because weeks == 0)
// (10.n.iii MoveRelativeDate not called because weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
]);
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
actual.splice(0); // clear
@ -225,6 +240,9 @@ const expectedOpsForWeekRounding = expected.concat([
"call this.calendar.dateUntil",
// RoundDuration
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
]); // (11.g.iii MoveRelativeDate not called because days already balanced)
// (11.g.iii MoveRelativeDate not called because days already balanced)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
]);
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");

View File

@ -166,7 +166,13 @@ const expectedOpsForYearRounding = expected.concat([
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateUntil", // 7.o
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.s not called because other units can't add up to >1 year at this point)
// (7.s not called because other units can't add up to >1 year at this point)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
@ -195,7 +201,13 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.o not called because months and weeks == 0)
// (7.o not called because months and weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherDatePropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months/weeks");
actual.splice(0); // clear
@ -211,7 +223,10 @@ const expectedOpsForMonthRounding = expected.concat([
"call this.calendar.dateAdd", // 10.c
"call this.calendar.dateAdd", // 10.e
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
]); // (10.n.iii MoveRelativeDate not called because weeks == 0)
// (10.n.iii MoveRelativeDate not called because weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
]);
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
@ -225,6 +240,9 @@ const expectedOpsForWeekRounding = expected.concat([
"call this.calendar.dateUntil",
// RoundDuration
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
]); // (11.g.iii MoveRelativeDate not called because days already balanced)
// (11.g.iii MoveRelativeDate not called because days already balanced)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
]);
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");

View File

@ -161,11 +161,18 @@ actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expected.concat([
// RoundDuration
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateUntil", // 7.o
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.s not called because other units can't add up to >1 year at this point)
// (7.s not called because other units can't add up to >1 year at this point)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
@ -181,16 +188,29 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.o not called because months and weeks == 0)
// (7.o not called because months and weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.since(otherYearMonthPropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years");
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months");
actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest month:
const expectedOpsForMonthRounding = expected.concat([
// RoundDuration
"call this.calendar.dateAdd", // 10.c
"call this.calendar.dateAdd", // 10.e
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
]); // (10.n.iii MoveRelativeDate not called because weeks == 0)
// (10.n.iii MoveRelativeDate not called because weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 2 }));
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");

View File

@ -20,5 +20,5 @@ const earlier = new Temporal.PlainYearMonth(2000, 5);
const later = new Temporal.PlainYearMonth(2000, 10);
const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" });
TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2");
const result2 = later.since(earlier, { smallestUnit: "months", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
const result2 = later.since(earlier, { largestUnit: "months", smallestUnit: "months", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
TemporalHelpers.assertDuration(result2, 0, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");

View File

@ -161,11 +161,18 @@ actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expected.concat([
// RoundDuration
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateUntil", // 7.o
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.s not called because other units can't add up to >1 year at this point)
// (7.s not called because other units can't add up to >1 year at this point)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
@ -181,17 +188,30 @@ const expectedOpsForYearRoundingSameMonth = expected.concat([
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.o not called because months and weeks == 0)
// (7.o not called because months and weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherYearMonthPropertyBagSameMonth, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years");
assert.compareArray(actual, expectedOpsForYearRoundingSameMonth, "order of operations with smallestUnit = years and no excess months");
actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest month:
const expectedOpsForMonthRounding = expected.concat([
// RoundDuration
"call this.calendar.dateAdd", // 10.c
"call this.calendar.dateAdd", // 10.e
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
]); // (10.n.iii MoveRelativeDate not called because weeks == 0)
// (10.n.iii MoveRelativeDate not called because weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 2 }));
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
actual.splice(0); // clear

View File

@ -20,5 +20,5 @@ const earlier = new Temporal.PlainYearMonth(2000, 5);
const later = new Temporal.PlainYearMonth(2000, 10);
const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" });
TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2");
const result2 = earlier.until(later, { smallestUnit: "months", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
const result2 = earlier.until(later, { largestUnit: "months", smallestUnit: "months", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
TemporalHelpers.assertDuration(result2, 0, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");

View File

@ -29,8 +29,9 @@ assert.sameValue(calendar.dateAddCallCount, 1, "basic difference with largestUni
// RoundDuration ->
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
// MoveRelativeDate -> calendar.dateAdd()
// BalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd()
calendar.dateAddCallCount = 0;
later1.since(earlier, { smallestUnit: "weeks" });
assert.sameValue(calendar.dateAddCallCount, 3, "rounding difference with calendar smallestUnit");
assert.sameValue(calendar.dateAddCallCount, 4, "rounding difference with calendar smallestUnit");

View File

@ -77,7 +77,7 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
later.since(earlier, { largestUnit, roundingIncrement: 2, roundingMode: 'ceil' });
},
{
years: ["year", "year"],
years: ["year", "year", "month"],
months: ["month", "month"],
weeks: ["week", "week"],
days: [],
@ -100,7 +100,7 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
later.since(earlier, { smallestUnit });
},
{
years: ["year", "year"],
years: ["year", "year", "month"],
months: ["month"],
weeks: ["week"],
days: [],

View File

@ -358,29 +358,44 @@ actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expected.concat(expectedOpsForCalendarDifference, expectedOpsForCalendarRounding, [
// RoundDuration
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateUntil", // 7.o
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.s not called because other units can't add up to >1 year at this point)
// (7.s not called because other units can't add up to >1 year at this point)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest month:
const expectedOpsForMonthRounding = expected.concat(expectedOpsForCalendarDifference, expectedOpsForCalendarRounding, [
// RoundDuration
"call this.calendar.dateAdd", // 10.c
"call this.calendar.dateAdd", // 10.e
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
]); // (10.n.iii MoveRelativeDate not called because weeks == 0)
// (10.n.iii MoveRelativeDate not called because weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
]);
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest week:
const expectedOpsForWeekRounding = expected.concat(expectedOpsForCalendarDifference, expectedOpsForCalendarRounding, [
// RoundDuration
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
]); // (11.g.iii MoveRelativeDate not called because days already balanced)
// (11.g.iii MoveRelativeDate not called because days already balanced)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
]);
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
actual.splice(0); // clear

View File

@ -29,8 +29,9 @@ assert.sameValue(calendar.dateAddCallCount, 1, "basic difference with largestUni
// RoundDuration ->
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
// MoveRelativeDate -> calendar.dateAdd()
// BalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd()
calendar.dateAddCallCount = 0;
earlier.until(later1, { smallestUnit: "weeks" });
assert.sameValue(calendar.dateAddCallCount, 3, "rounding difference with calendar smallestUnit");
assert.sameValue(calendar.dateAddCallCount, 4, "rounding difference with calendar smallestUnit");

View File

@ -77,7 +77,7 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
earlier.until(later, { largestUnit, roundingIncrement: 2, roundingMode: 'ceil' });
},
{
years: ["year", "year"],
years: ["year", "year", "month"],
months: ["month", "month"],
weeks: ["week", "week"],
days: [],
@ -100,7 +100,7 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
earlier.until(later, { smallestUnit });
},
{
years: ["year", "year"],
years: ["year", "year", "month"],
months: ["month"],
weeks: ["week"],
days: [],

View File

@ -358,29 +358,44 @@ actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expected.concat(expectedOpsForCalendarDifference, expectedOpsForCalendarRounding, [
// RoundDuration
"call this.calendar.dateAdd", // 7.e
"call this.calendar.dateAdd", // 7.g
"call this.calendar.dateUntil", // 7.o
"call this.calendar.dateAdd", // 7.y MoveRelativeDate
]); // (7.s not called because other units can't add up to >1 year at this point)
// (7.s not called because other units can't add up to >1 year at this point)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 11.c MoveRelativeDate
"call this.calendar.dateAdd", // 11.g MoveRelativeDate
"call this.calendar.dateAdd", // 11.k
"call this.calendar.dateUntil" // 11.n
]);
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest month:
const expectedOpsForMonthRounding = expected.concat(expectedOpsForCalendarDifference, expectedOpsForCalendarRounding, [
// RoundDuration
"call this.calendar.dateAdd", // 10.c
"call this.calendar.dateAdd", // 10.e
"call this.calendar.dateAdd", // 10.k MoveRelativeDate
]); // (10.n.iii MoveRelativeDate not called because weeks == 0)
// (10.n.iii MoveRelativeDate not called because weeks == 0)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 12.b MoveRelativeDate
]);
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "months" }));
assert.compareArray(actual, expectedOpsForMonthRounding, "order of operations with smallestUnit = months");
actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest week:
const expectedOpsForWeekRounding = expected.concat(expectedOpsForCalendarDifference, expectedOpsForCalendarRounding, [
// RoundDuration
"call this.calendar.dateAdd", // 11.d MoveRelativeDate
]); // (11.g.iii MoveRelativeDate not called because days already balanced)
// (11.g.iii MoveRelativeDate not called because days already balanced)
// BalanceDurationRelative
"call this.calendar.dateAdd", // 13.c MoveRelativeDate
]);
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "weeks" }));
assert.compareArray(actual, expectedOpsForWeekRounding, "order of operations with smallestUnit = weeks");
actual.splice(0); // clear