Temporal: Call user code on relativeTo only when necessary in RoundDuration

This commit is contained in:
Philip Chimento 2023-03-03 14:50:31 -08:00 committed by Ms2ger
parent f44bbe4035
commit 0a6341de65
5 changed files with 13 additions and 23 deletions

View File

@ -327,9 +327,6 @@ const expectedOpsForZonedRelativeTo = [
"get options.smallestUnit", "get options.smallestUnit",
"get options.smallestUnit.toString", "get options.smallestUnit.toString",
"call options.smallestUnit.toString", "call options.smallestUnit.toString",
// RoundDuration → ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
]; ];
const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, { const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
@ -376,6 +373,9 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
"call options.relativeTo.calendar.dateAdd", "call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor "get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor", "call options.relativeTo.timeZone.getPossibleInstantsFor",
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 9.b "get options.relativeTo.calendar.dateAdd", // 9.b
"call options.relativeTo.calendar.dateAdd", // 9.c "call options.relativeTo.calendar.dateAdd", // 9.c
"call options.relativeTo.calendar.dateAdd", // 9.e "call options.relativeTo.calendar.dateAdd", // 9.e

View File

@ -43,7 +43,6 @@ let zdt = new Temporal.ZonedDateTime(
timeZoneSubstituteValues( timeZoneSubstituteValues(
[[epochInstant]], // Returned for NanosecondsToDays step 14, setting _intermediateNs_ [[epochInstant]], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
[ [
0, // Returned for RoundDuration step 6.c.i, setting _intermediate_ - making _startNs_ 0 in NanosecondsToDays
dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_ dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
-dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_ -dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
] ]
@ -64,7 +63,6 @@ zdt = new Temporal.ZonedDateTime(
timeZoneSubstituteValues( timeZoneSubstituteValues(
[[epochInstant]], // Returned for NanosecondsToDays step 14, setting _intermediateNs_ [[epochInstant]], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
[ [
0, // Returned for RoundDuration step 6.c.i, setting _intermediate_ - making _startNs_ 0 in NanosecondsToDays
-dayNs + 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_ -dayNs + 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
dayNs - 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_ dayNs - 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
] ]
@ -88,7 +86,6 @@ zdt = new Temporal.ZonedDateTime(
[new Temporal.Instant(-4n)], // Returned for NanosecondsToDays step 18.a, setting _oneDayFartherNs_ [new Temporal.Instant(-4n)], // Returned for NanosecondsToDays step 18.a, setting _oneDayFartherNs_
], ],
[ [
0, // Returned for RoundDuration step 6.c.i, setting _intermediate_ - making _startNs_ 0 in NanosecondsToDays
dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_ dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
-dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_ -dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
] ]

View File

@ -255,14 +255,7 @@ const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
// basic order of observable operations, without rounding: // basic order of observable operations, without rounding:
instance.total(createOptionsObserver({ unit: "nanoseconds", relativeTo: zonedRelativeTo })); instance.total(createOptionsObserver({ unit: "nanoseconds", relativeTo: zonedRelativeTo }));
assert.compareArray( assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations for ZonedDateTime relativeTo");
actual,
expectedOpsForZonedRelativeTo.concat([
// RoundDuration → ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
]),
"order of operations for ZonedDateTime relativeTo");
actual.splice(0); // clear actual.splice(0); // clear
const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
@ -288,9 +281,6 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor "get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor", "call options.relativeTo.timeZone.getPossibleInstantsFor",
], [ ], [
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// code path through RoundDuration that rounds to the nearest year: // code path through RoundDuration that rounds to the nearest year:
// MoveRelativeZonedDateTime → AddZonedDateTime // MoveRelativeZonedDateTime → AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor "get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
@ -299,6 +289,9 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
"call options.relativeTo.calendar.dateAdd", "call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor "get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor", "call options.relativeTo.timeZone.getPossibleInstantsFor",
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 9.b "get options.relativeTo.calendar.dateAdd", // 9.b
"call options.relativeTo.calendar.dateAdd", // 9.c "call options.relativeTo.calendar.dateAdd", // 9.c
"call options.relativeTo.calendar.dateAdd", // 9.e "call options.relativeTo.calendar.dateAdd", // 9.e

View File

@ -189,9 +189,6 @@ const expectedOpsForCalendarDifference = [
]; ];
const expectedOpsForCalendarRounding = [ const expectedOpsForCalendarRounding = [
// RoundDuration → ToTemporalDate
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"get this.timeZone.getOffsetNanosecondsFor", "get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor", "call this.timeZone.getOffsetNanosecondsFor",
@ -214,6 +211,9 @@ const expectedOpsForCalendarRounding = [
"call this.calendar.dateAdd", "call this.calendar.dateAdd",
"get this.timeZone.getPossibleInstantsFor", "get this.timeZone.getPossibleInstantsFor",
"call this.timeZone.getPossibleInstantsFor", "call this.timeZone.getPossibleInstantsFor",
// RoundDuration → ToTemporalDate
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
]; ];
// code path that skips RoundDuration: // code path that skips RoundDuration:

View File

@ -189,9 +189,6 @@ const expectedOpsForCalendarDifference = [
]; ];
const expectedOpsForCalendarRounding = [ const expectedOpsForCalendarRounding = [
// RoundDuration → ToTemporalDate
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime // RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"get this.timeZone.getOffsetNanosecondsFor", "get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor", "call this.timeZone.getOffsetNanosecondsFor",
@ -214,6 +211,9 @@ const expectedOpsForCalendarRounding = [
"call this.calendar.dateAdd", "call this.calendar.dateAdd",
"get this.timeZone.getPossibleInstantsFor", "get this.timeZone.getPossibleInstantsFor",
"call this.timeZone.getPossibleInstantsFor", "call this.timeZone.getPossibleInstantsFor",
// RoundDuration → ToTemporalDate
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
]; ];
// code path that skips RoundDuration: // code path that skips RoundDuration: