Skip to content

Commit

Permalink
Temporal: Precalculate PlainDateTime from ZonedDateTime in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed Sep 14, 2023
1 parent e0c083a commit 742f71c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// MoveRelativeZonedDateTime → AddZonedDateTime
"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",
Expand Down Expand Up @@ -456,8 +454,6 @@ const expectedOpsForUnbalanceRoundBalance = expectedOpsForZonedRelativeTo.concat
"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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let zdt = new Temporal.ZonedDateTime(
timeZoneSubstituteValues(
[[epochInstant]], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
[
TemporalHelpers.SUBSTITUTE_SKIP, // Pre-conversion in Duration.p.round
dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
-dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
]
Expand All @@ -63,6 +64,7 @@ zdt = new Temporal.ZonedDateTime(
timeZoneSubstituteValues(
[[epochInstant]], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
[
TemporalHelpers.SUBSTITUTE_SKIP, // Pre-conversion in Duration.p.round
-dayNs + 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
dayNs - 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
]
Expand All @@ -86,6 +88,7 @@ zdt = new Temporal.ZonedDateTime(
[new Temporal.Instant(-4n)], // Returned for NanosecondsToDays step 18.a, setting _oneDayFartherNs_
],
[
TemporalHelpers.SUBSTITUTE_SKIP, // Pre-conversion in Duration.p.round
dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
-dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,6 @@ const expectedOpsForMinimalYearRoundingZoned = expectedOpsForZonedRelativeTo.con
], [
// code path through RoundDuration that rounds to the nearest year:
// MoveRelativeZonedDateTime → AddDaysToZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.calendar.dateAdd", // 7.c
Expand All @@ -315,8 +313,6 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// MoveRelativeZonedDateTime → AddZonedDateTime
"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",
Expand All @@ -333,8 +329,6 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
"get options.relativeTo.timeZone.getPossibleInstantsFor",
"call options.relativeTo.timeZone.getPossibleInstantsFor",
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"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",
Expand Down Expand Up @@ -363,15 +357,11 @@ const expectedOpsForUnbalanceRound = expectedOpsForZonedRelativeTo.concat([
"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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let zdt = new Temporal.ZonedDateTime(
timeZoneSubstituteValues(
[[epochInstant]], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
[
TemporalHelpers.SUBSTITUTE_SKIP, // pre-conversion in Duration.p.total
dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
-dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
]
Expand All @@ -63,6 +64,7 @@ zdt = new Temporal.ZonedDateTime(
timeZoneSubstituteValues(
[[epochInstant]], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
[
TemporalHelpers.SUBSTITUTE_SKIP, // pre-conversion in Duration.p.total
-dayNs + 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
dayNs - 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
]
Expand All @@ -86,6 +88,7 @@ zdt = new Temporal.ZonedDateTime(
[new Temporal.Instant(-4n)], // Returned for NanosecondsToDays step 18.a, setting _oneDayFartherNs_
],
[
TemporalHelpers.SUBSTITUTE_SKIP, // pre-conversion in Duration.p.total
dayNs - 1, // Returned for NanosecondsToDays step 7, setting _startDateTime_
-dayNs + 1, // Returned for NanosecondsToDays step 11, setting _endDateTime_
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,10 @@ const expectedOpsForCalendarDifference = [
// TimeZoneEquals
"get this.timeZone.id",
"get other.timeZone.id",
// DifferenceZonedDateTime
// precalculate PlainDateTime
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// DifferenceZonedDateTime
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// DifferenceISODateTime
Expand All @@ -344,12 +345,7 @@ const expectedOpsForCalendarDifference = [
];

const expectedOpsForCalendarRounding = [
// ToTemporalDate
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
"get this.calendar.dateAdd",
"call this.calendar.dateAdd",
"get this.timeZone.getPossibleInstantsFor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,10 @@ const expectedOpsForCalendarDifference = [
// TimeZoneEquals
"get this.timeZone.id",
"get other.timeZone.id",
// DifferenceZonedDateTime
// precalculate PlainDateTime
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// DifferenceZonedDateTime
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// DifferenceISODateTime
Expand All @@ -344,12 +345,7 @@ const expectedOpsForCalendarDifference = [
];

const expectedOpsForCalendarRounding = [
// ToTemporalDate
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
// RoundDuration → MoveRelativeZonedDateTime → AddZonedDateTime
"get this.timeZone.getOffsetNanosecondsFor",
"call this.timeZone.getOffsetNanosecondsFor",
"get this.calendar.dateAdd",
"call this.calendar.dateAdd",
"get this.timeZone.getPossibleInstantsFor",
Expand Down

0 comments on commit 742f71c

Please sign in to comment.