Skip to content

Commit

Permalink
Adjustments to tests for added invocations of BalanceDurationRelative
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ptomato committed Jun 20, 2023
1 parent 89eac4a commit d668abb
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ const expectedOpsForYearRounding = expected.concat([
"call this.calendar.dateAdd", // 7.f
"call this.calendar.dateUntil", // 7.n
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
]); // (7.s not called because FIXME; add an example where it is called)
// (7.s not called because FIXME; add an example where it is called)
// 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
Expand All @@ -139,7 +145,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
Expand All @@ -153,6 +162,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.slice(expected.length), expectedOpsForWeekRounding.slice(expected.length), "order of operations with smallestUnit = weeks");
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ const expectedOpsForYearRounding = expected.concat([
"call this.calendar.dateAdd", // 7.f
"call this.calendar.dateUntil", // 7.n
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
]); // (7.s not called because FIXME; add an example where it is called)
// (7.s not called because FIXME; add an example where it is called)
// 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
Expand All @@ -139,7 +145,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
Expand All @@ -153,6 +162,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.slice(expected.length), expectedOpsForWeekRounding.slice(expected.length), "order of operations with smallestUnit = weeks");
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ const expectedOpsForYearRounding = expected.concat([
"call this.calendar.dateAdd", // 7.f
"call this.calendar.dateUntil", // 7.n
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
]); // (7.s not called because FIXME; add an example where it is called)
// (7.s not called because FIXME; add an example where it is called)
// 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
Expand All @@ -163,7 +169,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
Expand All @@ -177,6 +186,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.slice(expected.length), expectedOpsForWeekRounding.slice(expected.length), "order of operations with smallestUnit = weeks");
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ const expectedOpsForYearRounding = expected.concat([
"call this.calendar.dateAdd", // 7.f
"call this.calendar.dateUntil", // 7.n
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
]); // (7.s not called because FIXME; add an example where it is called)
// (7.s not called because FIXME; add an example where it is called)
// 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
Expand All @@ -163,7 +169,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
Expand All @@ -177,6 +186,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.slice(expected.length), expectedOpsForWeekRounding.slice(expected.length), "order of operations with smallestUnit = weeks");
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,34 @@ actual.splice(0);

// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expected.concat([
// RoundDuration
"call this.calendar.dateAdd", // 7.d
"call this.calendar.dateAdd", // 7.f
"call this.calendar.dateUntil", // 7.n
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
]); // (7.s not called because FIXME; add an example where it is called)
// (7.s not called because FIXME; add an example where it is called)
// 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

// 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");
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,35 @@ actual.splice(0);

// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expected.concat([
// RoundDuration
"call this.calendar.dateAdd", // 7.d
"call this.calendar.dateAdd", // 7.f
"call this.calendar.dateUntil", // 7.n
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
]); // (7.s not called because FIXME; add an example where it is called)
// (7.s not called because FIXME; add an example where it is called)
// 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

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ assert.sameValue(calendar.dateAddCallCount, 1, "basic difference with largestUni
// RoundDuration ->
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> 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");
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -100,7 +100,7 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
later.since(earlier, { smallestUnit });
},
{
years: ["year", "year"],
years: ["year", "year", "month"],
months: ["month"],
weeks: ["week"],
days: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,29 +183,44 @@ const expectedOpsForCalendarDifference = [

// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expected.concat(expectedOpsForCalendarDifference, [
// RoundDuration
"call this.calendar.dateAdd", // 7.d
"call this.calendar.dateAdd", // 7.f
"call this.calendar.dateUntil", // 7.n
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
]); // (7.s not called because FIXME; add an example where it is called)
// (7.s not called because FIXME; add an example where it is called)
// 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, [
// 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, [
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ assert.sameValue(calendar.dateAddCallCount, 1, "basic difference with largestUni
// RoundDuration ->
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> 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");
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -100,7 +100,7 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
earlier.until(later, { smallestUnit });
},
{
years: ["year", "year"],
years: ["year", "year", "month"],
months: ["month"],
weeks: ["week"],
days: [],
Expand Down
Loading

0 comments on commit d668abb

Please sign in to comment.