Skip to content

Commit

Permalink
Temporal: Look up time zone methods only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed Nov 6, 2023
1 parent c1281db commit 911fe96
Show file tree
Hide file tree
Showing 28 changed files with 139 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"has options.relativeTo.timeZone.getOffsetNanosecondsFor",
"has options.relativeTo.timeZone.getPossibleInstantsFor",
"has options.relativeTo.timeZone.id",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
]);

Expand Down Expand Up @@ -291,13 +291,10 @@ Temporal.Duration.compare(
assert.compareArray(
actual,
expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDaysToZonedDateTime on first argument
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDaysToZonedDateTime on second argument
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
]),
"order of operations with ZonedDateTime relativeTo and no calendar units except days"
Expand Down Expand Up @@ -326,17 +323,14 @@ Temporal.Duration.compare(
assert.compareArray(
actual,
expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddZonedDateTime on first argument
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddZonedDateTime on second argument
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
]),
"order of operations with ZonedDateTime relativeTo and calendar units"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ const expected = [
"has timeZone.getOffsetNanosecondsFor",
"has timeZone.getPossibleInstantsFor",
"has timeZone.id",
// lookup
"get timeZone.getOffsetNanosecondsFor",
"get timeZone.getPossibleInstantsFor",
// InterpretISODateTimeOffset
"call timeZone.getPossibleInstantsFor",
];

const expectedSpringForward = expected.concat([
// InterpretISODateTimeOffset
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
// DisambiguatePossibleInstants
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
]);
assert.compareArray(
Expand All @@ -81,14 +81,9 @@ actual.splice(0); // clear
relativeTo = { year: 2000, month: 10, day: 29, hour: 1, minute: 30, timeZone: dstTimeZoneObserver, calendar };
Temporal.Duration.compare(duration1, duration2, {relativeTo: relativeTo});

const expectedFallBack = expected.concat([
// InterpretISODateTimeOffset
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
]);
assert.compareArray(
actual.slice(0, expectedFallBack.length), // ignore operations after ToRelativeTemporalObject
expectedFallBack,
actual.slice(0, expected.length), // ignore operations after ToRelativeTemporalObject
expected,
"order of operations converting property bag at repeated wall-clock time"
);
actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -316,46 +316,36 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"has options.relativeTo.timeZone.getPossibleInstantsFor",
"has options.relativeTo.timeZone.id",
// InterpretISODateTimeOffset
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → AddZonedDateTime 1
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDuration → AddZonedDateTime 2
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDuration → DifferenceZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → DifferenceZonedDateTime → DifferenceISODateTime
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateUntil",
// AddDuration → DifferenceZonedDateTime → AddZonedDateTime
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDuration → DifferenceZonedDateTime → NanosecondsToDays
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → DifferenceZonedDateTime → NanosecondsToDays → AddZonedDateTime 1
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDuration → DifferenceZonedDateTime → NanosecondsToDays → AddZonedDateTime 2
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ const expected = [
"has timeZone.getOffsetNanosecondsFor",
"has timeZone.getPossibleInstantsFor",
"has timeZone.id",
// lookup
"get timeZone.getOffsetNanosecondsFor",
"get timeZone.getPossibleInstantsFor",
// InterpretISODateTimeOffset
"call timeZone.getPossibleInstantsFor",
];

const expectedSpringForward = expected.concat([
// InterpretISODateTimeOffset
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
// DisambiguatePossibleInstants
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
]);
assert.compareArray(
Expand All @@ -80,14 +80,9 @@ actual.splice(0); // clear
relativeTo = { year: 2000, month: 10, day: 29, hour: 1, minute: 30, timeZone: dstTimeZoneObserver, calendar };
instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo });

const expectedFallBack = expected.concat([
// InterpretISODateTimeOffset
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
]);
assert.compareArray(
actual.slice(0, expectedFallBack.length), // ignore operations after ToRelativeTemporalObject
expectedFallBack,
actual.slice(0, expected.length), // ignore operations after ToRelativeTemporalObject
expected,
"order of operations converting property bag at repeated wall-clock time"
);
actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ const expectedOpsForZonedRelativeTo = [
"has options.relativeTo.timeZone.getOffsetNanosecondsFor",
"has options.relativeTo.timeZone.getPossibleInstantsFor",
"has options.relativeTo.timeZone.id",
// InterpretISODateTimeOffset
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
// InterpretISODateTimeOffset
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.roundingIncrement",
"get options.roundingIncrement.valueOf",
Expand Down Expand Up @@ -373,18 +373,13 @@ actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest year with minimal calendar operations:
const expectedOpsForMinimalYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// NanosecondsToDays
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 11. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 11. GetPlainDateTimeFor
// NanosecondsToDays → AddDaysToZonedDateTime
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// NanosecondsToDays → AddDaysToZonedDateTime
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// RoundDuration
"get options.relativeTo.calendar.dateAdd", // 7.c
Expand All @@ -405,23 +400,17 @@ actual.splice(0); // clear
// code path through RoundDuration that rounds to the nearest year:
const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// MoveRelativeZonedDateTime → AddZonedDateTime
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// NanosecondsToDays
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 11. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 8. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 9. GetPlainDateTimeFor
// NanosecondsToDays → AddDaysToZonedDateTime
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// NanosecondsToDays → AddDaysToZonedDateTime
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.calendar.dateAdd", // 7.c
"call options.relativeTo.calendar.dateAdd", // 7.e
Expand Down Expand Up @@ -450,14 +439,12 @@ actual.splice(0); // clear
// BalanceDateDurationRelative
const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// No user code calls in UnbalanceDurationRelative
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"get options.relativeTo.calendar.dateAdd", // 8.
"get options.relativeTo.calendar.dateAdd", // 11.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor", // 13. GetInstantFor
// RoundDuration
"get options.relativeTo.calendar.dateAdd", // 8.e.i
"call options.relativeTo.calendar.dateAdd", // 8.g MoveRelativeDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ const expected = [
"has timeZone.getOffsetNanosecondsFor",
"has timeZone.getPossibleInstantsFor",
"has timeZone.id",
// lookup
"get timeZone.getOffsetNanosecondsFor",
"get timeZone.getPossibleInstantsFor",
// InterpretISODateTimeOffset
"call timeZone.getPossibleInstantsFor",
];

const expectedSpringForward = expected.concat([
// InterpretISODateTimeOffset
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
// DisambiguatePossibleInstants
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
]);
assert.compareArray(
Expand All @@ -80,14 +80,9 @@ actual.splice(0); // clear
relativeTo = { year: 2000, month: 10, day: 29, hour: 1, minute: 30, timeZone: dstTimeZoneObserver, calendar };
instance.round({ largestUnit: "years", relativeTo });

const expectedFallBack = expected.concat([
// InterpretISODateTimeOffset
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
]);
assert.compareArray(
actual.slice(0, expectedFallBack.length), // ignore operations after ToRelativeTemporalObject
expectedFallBack,
actual.slice(0, expected.length), // ignore operations after ToRelativeTemporalObject
expected,
"order of operations converting property bag at repeated wall-clock time"
);
actual.splice(0); // clear
Original file line number Diff line number Diff line change
Expand Up @@ -316,46 +316,36 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"has options.relativeTo.timeZone.getPossibleInstantsFor",
"has options.relativeTo.timeZone.id",
// InterpretISODateTimeOffset
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → AddZonedDateTime 1
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDuration → AddZonedDateTime 2
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDuration → DifferenceZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → DifferenceZonedDateTime → DifferenceISODateTime
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateUntil",
// AddDuration → DifferenceZonedDateTime → AddZonedDateTime
"get options.relativeTo.calendar.dateAdd",
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDuration → DifferenceZonedDateTime → NanosecondsToDays
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → DifferenceZonedDateTime → NanosecondsToDays → AddZonedDateTime 1
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// AddDuration → DifferenceZonedDateTime → NanosecondsToDays → AddZonedDateTime 2
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ const expected = [
"has timeZone.getOffsetNanosecondsFor",
"has timeZone.getPossibleInstantsFor",
"has timeZone.id",
// lookup
"get timeZone.getOffsetNanosecondsFor",
"get timeZone.getPossibleInstantsFor",
// InterpretISODateTimeOffset
"call timeZone.getPossibleInstantsFor",
];

const expectedSpringForward = expected.concat([
// InterpretISODateTimeOffset
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
// DisambiguatePossibleInstants
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
]);
assert.compareArray(
Expand All @@ -80,14 +80,9 @@ actual.splice(0); // clear
relativeTo = { year: 2000, month: 10, day: 29, hour: 1, minute: 30, timeZone: dstTimeZoneObserver, calendar };
instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo });

const expectedFallBack = expected.concat([
// InterpretISODateTimeOffset
"get timeZone.getPossibleInstantsFor",
"call timeZone.getPossibleInstantsFor",
]);
assert.compareArray(
actual.slice(0, expectedFallBack.length), // ignore operations after ToRelativeTemporalObject
expectedFallBack,
actual.slice(0, expected.length), // ignore operations after ToRelativeTemporalObject
expected,
"order of operations converting property bag at repeated wall-clock time"
);
actual.splice(0); // clear
Loading

0 comments on commit 911fe96

Please sign in to comment.