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 Sep 19, 2023
1 parent 55e5412 commit 7b983b3
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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");
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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");
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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");
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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");
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
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 @@ -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
Expand All @@ -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
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 @@ -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");
Loading

0 comments on commit 7b983b3

Please sign in to comment.