Skip to content

Commit

Permalink
Temporal: Make calendar method lookups unconditional
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed Nov 10, 2023
1 parent 7bfb70b commit 8f04058
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ const expectedOpsForPlainRelativeTo = expected.concat([
"get options.relativeTo.year.valueOf",
"call options.relativeTo.year.valueOf",
"call options.relativeTo.calendar.dateFromFields",
// lookup
"get options.relativeTo.calendar.dateAdd",
]);

const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
Expand Down Expand Up @@ -176,7 +178,6 @@ actual.splice(0); // clear
// to days:
const expectedOpsForPlainDayBalancing = expectedOpsForPlainRelativeTo.concat(
[
"get options.relativeTo.calendar.dateAdd",
// UnbalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
Expand Down Expand Up @@ -264,6 +265,8 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup
"get options.relativeTo.calendar.dateAdd",
]);

const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
Expand Down Expand Up @@ -323,7 +326,6 @@ Temporal.Duration.compare(
assert.compareArray(
actual,
expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddZonedDateTime on first argument
"call options.relativeTo.calendar.dateAdd",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ const expectedOpsForPlainRelativeToNoCalendarOperations = [
"call options.relativeTo.year.valueOf",
// InterpretTemporalDateTimeFields
"call options.relativeTo.calendar.dateFromFields",
// lookup 2
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const noCalendarInstance = new Temporal.Duration(0, 0, 0, 4, 5, 6, 7, 987, 654, 321);
Expand Down Expand Up @@ -469,6 +472,9 @@ const expectedOpsForZonedRelativeToNoDaysOperations = [
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup 2
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const noDaysInstance = new Temporal.Duration(0, 0, 0, 0, 5, 6, 7, 987, 654, 321);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const expectedOpsForPlainRelativeTo = [
"get options.smallestUnit",
"get options.smallestUnit.toString",
"call options.smallestUnit.toString",
// lookup
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
Expand All @@ -119,8 +122,6 @@ actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year, with minimal calendar calls:
const expectedMinimalOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// 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
Expand All @@ -132,8 +133,6 @@ actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateAdd", // 7.e
"call options.relativeTo.calendar.dateAdd", // 7.g
"call options.relativeTo.calendar.dateUntil", // 7.o
Expand All @@ -152,8 +151,6 @@ actual.splice(0); // clear

// code path through Duration.prototype.round that rounds to the nearest month:
const expectedOpsForMonthRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// UnbalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 9.d.i
"call options.relativeTo.calendar.dateUntil", // 9.d.iv
Expand All @@ -172,7 +169,6 @@ actual.splice(0); // clear

// code path through Duration.prototype.round that rounds to the nearest week:
const expectedOpsForWeekRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
// UnbalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 10.c.i MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 10.d.i MoveRelativeDate
Expand All @@ -189,7 +185,6 @@ actual.splice(0); // clear

// code path through UnbalanceDurationRelative that rounds to the nearest day:
const expectedOpsForDayRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
Expand All @@ -201,8 +196,6 @@ actual.splice(0); // clear

// code path through BalanceDurationRelative balancing from days up to years:
const expectedOpsForDayToYearBalancing = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateAdd", // 10.b MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 10.e.iv MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 10.f MoveRelativeDate
Expand All @@ -217,8 +210,6 @@ actual.splice(0); // clear

// code path through Duration.prototype.round balancing from months up to years:
const expectedOpsForMonthToYearBalancing = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// RoundDuration
"call options.relativeTo.calendar.dateAdd", // 10.c
"call options.relativeTo.calendar.dateAdd", // 10.e
Expand All @@ -237,7 +228,6 @@ assert.compareArray(actual, expectedOpsForMonthToYearBalancing, "order of operat
actual.splice(0); // clear

const expectedOpsForDayToMonthBalancing = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
// BalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 11.b MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.e.iv MoveRelativeDate
Expand All @@ -248,7 +238,6 @@ assert.compareArray(actual, expectedOpsForDayToMonthBalancing, "order of operati
actual.splice(0); // clear

const expectedOpsForDayToWeekBalancing = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
// BalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 12.c MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 12.f.iv MoveRelativeDate
Expand Down Expand Up @@ -360,7 +349,10 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {

// basic order of operations with ZonedDateTime relativeTo:
instance.round(createOptionsObserver({ relativeTo: zonedRelativeTo }));
assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations for ZonedDateTime relativeTo");
assert.compareArray(actual, expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
]), "order of operations for ZonedDateTime relativeTo");
actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year with minimal calendar operations:
Expand Down Expand Up @@ -434,6 +426,7 @@ const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// No user code calls in UnbalanceDurationRelative
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"call options.relativeTo.calendar.dateAdd",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ const expectedOpsForPlainRelativeToNoCalendarOperations = [
"call options.relativeTo.year.valueOf",
// InterpretTemporalDateTimeFields
"call options.relativeTo.calendar.dateFromFields",
// lookup 2
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const noCalendarInstance = new Temporal.Duration(0, 0, 0, 4, 5, 6, 7, 987, 654, 321);
Expand Down Expand Up @@ -469,6 +472,9 @@ const expectedOpsForZonedRelativeToNoDaysOperations = [
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup 2
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const noDaysInstance = new Temporal.Duration(0, 0, 0, 0, 5, 6, 7, 987, 654, 321);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ const expectedOpsForPlainRelativeTo = [
"get options.unit",
"get options.unit.toString",
"call options.unit.toString",
// lookup
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
];

const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
Expand All @@ -102,9 +105,6 @@ actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year with minimal calendar calls:
const expectedOpsForMinimalYearRounding = expectedOpsForPlainRelativeTo.concat([
// lookup
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// 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
Expand All @@ -116,8 +116,6 @@ actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateAdd", // 7.d
"call options.relativeTo.calendar.dateAdd", // 7.f
"call options.relativeTo.calendar.dateUntil", // 7.n
Expand All @@ -131,8 +129,6 @@ actual.splice(0); // clear

// code path through Duration.prototype.total that rounds to the nearest month:
const expectedOpsForMonthRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// UnbalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 9.d.i
"call options.relativeTo.calendar.dateUntil", // 9.d.iv
Expand All @@ -148,7 +144,6 @@ actual.splice(0); // clear

// code path through Duration.prototype.total that rounds to the nearest week:
const expectedOpsForWeekRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
// UnbalanceDurationRelative
"call options.relativeTo.calendar.dateAdd", // 10.c.i MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 10.d.i MoveRelativeDate
Expand All @@ -162,7 +157,6 @@ actual.splice(0); // clear

// code path through UnbalanceDurationRelative that rounds to the nearest day:
const expectedOpsForDayRounding = expectedOpsForPlainRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd", // 11.a.iii.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.iv.1 MoveRelativeDate
"call options.relativeTo.calendar.dateAdd", // 11.a.v.1 MoveRelativeDate
Expand Down Expand Up @@ -267,7 +261,10 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {

// basic order of observable operations, without rounding:
instance.total(createOptionsObserver({ unit: "nanoseconds", relativeTo: zonedRelativeTo }));
assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations for ZonedDateTime relativeTo");
assert.compareArray(actual, expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
]), "order of operations for ZonedDateTime relativeTo");
actual.splice(0); // clear

// code path through RoundDuration that rounds to the nearest year with minimal calendar operations:
Expand Down Expand Up @@ -341,6 +338,7 @@ const expectedOpsForUnbalanceRound = expectedOpsForZonedRelativeTo.concat([
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup
"get options.relativeTo.calendar.dateAdd",
"get options.relativeTo.calendar.dateUntil",
// No user code calls in UnbalanceDateDurationRelative
// MoveRelativeZonedDateTime → AddZonedDateTime
"call options.relativeTo.calendar.dateAdd",
Expand All @@ -367,6 +365,7 @@ const expectedOpsForBalanceRound = expectedOpsForZonedRelativeTo.concat([
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// lookup
"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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const noCalendarExpected = [
"call fields.seconds.valueOf",
"get fields.weeks",
"get fields.years",
"get this.calendar.dateAdd",
// AddDate
"get options.overflow",
"get options.overflow.toString",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ actual.splice(0);
instance.since(otherDatePropertyBag, createOptionsObserver({ largestUnit: "years" }));
assert.compareArray(actual, expected.concat([
// lookup
"get this.calendar.dateAdd",
"get this.calendar.dateUntil",
// CalendarDateUntil
"call this.calendar.dateUntil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const noCalendarExpected = [
"call fields.seconds.valueOf",
"get fields.weeks",
"get fields.years",
"get this.calendar.dateAdd",
// AddDate
"get options.overflow",
"get options.overflow.toString",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ actual.splice(0);
instance.until(otherDatePropertyBag, createOptionsObserver({ largestUnit: "years" }));
assert.compareArray(actual, expected.concat([
// lookup
"get this.calendar.dateAdd",
"get this.calendar.dateUntil",
// CalendarDateUntil
"call this.calendar.dateUntil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const noCalendarExpected = [
"call fields.seconds.valueOf",
"get fields.weeks",
"get fields.years",
"get this.calendar.dateAdd",
// AddDateTime -> AddDate
"get options.overflow",
"get options.overflow.toString",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ actual.splice(0);
instance.since(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "years" }));
assert.compareArray(actual, expected.concat([
// lookup
"get this.calendar.dateAdd",
"get this.calendar.dateUntil",
// CalendarDateUntil
"call this.calendar.dateUntil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const noCalendarExpected = [
"call fields.seconds.valueOf",
"get fields.weeks",
"get fields.years",
"get this.calendar.dateAdd",
// AddDateTime -> AddDate
"get options.overflow",
"get options.overflow.toString",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ actual.splice(0);
instance.until(otherDateTimePropertyBag, createOptionsObserver({ largestUnit: "years" }));
assert.compareArray(actual, expected.concat([
// lookup
"get this.calendar.dateAdd",
"get this.calendar.dateUntil",
// CalendarDateUntil
"call this.calendar.dateUntil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const expected = [
// lookup
"get this.calendar.dateAdd",
"get this.calendar.dateFromFields",
"get this.calendar.day",
"get this.calendar.fields",
"get this.calendar.yearMonthFromFields",
// CalendarFields
Expand Down Expand Up @@ -129,7 +130,9 @@ const noCalendarExpected = [
"get fields.weeks",
"get fields.years",
// lookup
"get this.calendar.dateAdd",
"get this.calendar.dateFromFields",
"get this.calendar.day",
"get this.calendar.fields",
"get this.calendar.yearMonthFromFields",
// CalendarFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,7 @@ actual.splice(0);

// code path that skips RoundDuration:
instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "months", roundingIncrement: 1 }));
assert.compareArray(actual, expectedMinimal.concat([
// lookup
"get this.calendar.dateFromFields",
"get this.calendar.dateUntil",
"get this.calendar.fields",
// CalendarFields
"call this.calendar.fields",
// PrepareTemporalFields / CalendarDateFromFields (receiver)
"get this.calendar.monthCode",
"call this.calendar.monthCode",
"get this.calendar.year",
"call this.calendar.year",
"call this.calendar.dateFromFields",
// PrepareTemporalFields / CalendarDateFromFields (argument)
"get other.calendar.monthCode",
"call other.calendar.monthCode",
"get other.calendar.year",
"call other.calendar.year",
"call this.calendar.dateFromFields",
// CalendarDateUntil
"call this.calendar.dateUntil",
]), "order of operations with no rounding");
assert.compareArray(actual, expected, "order of operations with no rounding");
actual.splice(0); // clear

// short-circuit for identical objects:
Expand Down
Loading

0 comments on commit 8f04058

Please sign in to comment.