Skip to content

Commit

Permalink
fixup! Temporal: Precalculate PlainDateTime from ZonedDateTime in mor…
Browse files Browse the repository at this point in the history
…e places
  • Loading branch information
ptomato committed Sep 28, 2023
1 parent 15c728c commit 3f4e2c2
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,37 @@ assert.compareArray(
"order of operations with unit = months and ZonedDateTime relativeTo"
);
actual.splice(0); // clear

// code path that avoids converting Zoned twice in BalanceTimeDurationRelative
const expectedOpsForBalanceRound = expectedOpsForZonedRelativeTo.concat([
// ToTemporalDate
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// No user code calls in UnbalanceDateDurationRelative
// No user code calls in AddZonedDateTime (years, months, weeks = 0)
// BalanceTimeDurationRelative
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor", // 4.a
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor", // 4.b
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor", // NanosecondsToDays 9
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor", // NanosecondsToDays 26
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor", // NanosecondsToDays 31.a
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// RoundDuration
"get options.relativeTo.calendar.dateAdd", // 10.d.i
"call options.relativeTo.calendar.dateAdd", // 10.f
"call options.relativeTo.calendar.dateAdd", // 10.i.iii
]);
new Temporal.Duration(0, 0, 0, 1, 240).total(createOptionsObserver({ unit: "weeks", relativeTo: zonedRelativeTo }));
assert.compareArray(
actual,
expectedOpsForBalanceRound,
"order of operations with unit = weeks and no calendar units"
);
actual.splice(0); // clear

0 comments on commit 3f4e2c2

Please sign in to comment.