Temporal: Separate zoned and plain operations in RoundDuration

Adds new tests to order-of-operations.js in Duration.round and
Duration.total, to exercise the code path where previous to this normative
change, relativeTo would have been converted to PlainDate 3x and 2x,
respectively.
This commit is contained in:
Philip Chimento 2023-03-07 14:32:43 -08:00 committed by Ms2ger
parent 008b97932b
commit fdd44e2ea5
4 changed files with 75 additions and 12 deletions

View File

@ -352,6 +352,9 @@ 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",
// NanosecondsToDays
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
@ -373,9 +376,6 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 9.b
"call options.relativeTo.calendar.dateAdd", // 9.c
"call options.relativeTo.calendar.dateAdd", // 9.e
@ -392,3 +392,32 @@ assert.compareArray(
"order of operations with smallestUnit = years and ZonedDateTime relativeTo"
);
actual.splice(0); // clear
// code path that hits UnbalanceDateDurationRelative, RoundDuration, and
// 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.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 8.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// RoundDuration
"get options.relativeTo.calendar.dateAdd", // 8.e.i
"call options.relativeTo.calendar.dateAdd", // 8.g MoveRelativeDate
// BalanceDateDurationRelative
"get options.relativeTo.calendar.dateAdd", // 13.a.i
"call options.relativeTo.calendar.dateAdd", // 13.c MoveRelativeDate
]);
new Temporal.Duration(0, 1, 1).round(createOptionsObserver({ largestUnit: "months", smallestUnit: "weeks", relativeTo: zonedRelativeTo }));
assert.compareArray(
actual,
expectedOpsForUnbalanceRoundBalance,
"order of operations with largestUnit = months, smallestUnit = weeks, and ZonedDateTime relativeTo"
);
actual.splice(0); // clear

View File

@ -259,6 +259,9 @@ assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations
actual.splice(0); // clear
const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// BalancePossiblyInfiniteDuration → NanosecondsToDays
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 7. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
@ -289,9 +292,6 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 9.b
"call options.relativeTo.calendar.dateAdd", // 9.c
"call options.relativeTo.calendar.dateAdd", // 9.e
@ -308,3 +308,37 @@ assert.compareArray(
"order of operations with unit = years and ZonedDateTime relativeTo"
);
actual.splice(0); // clear
// code path that hits UnbalanceDateDurationRelative and RoundDuration
const expectedOpsForUnbalanceRound = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// No user code calls in UnbalanceDateDurationRelative
// MoveRelativeZonedDateTime → AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 8.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.calendar.dateAdd", // 8.
"call options.relativeTo.calendar.dateAdd",
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// RoundDuration
"get options.relativeTo.calendar.dateAdd", // 7.d.i
"call options.relativeTo.calendar.dateAdd", // 7.f
"call options.relativeTo.calendar.dateAdd", // 7.h
"call options.relativeTo.calendar.dateAdd", // 7.n MoveRelativeDate
]);
new Temporal.Duration(0, 1, 1).total(createOptionsObserver({ unit: "months", relativeTo: zonedRelativeTo }));
assert.compareArray(
actual,
expectedOpsForUnbalanceRound,
"order of operations with unit = months and ZonedDateTime relativeTo"
);
actual.splice(0); // clear

View File

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

View File

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