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 feb36c0
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → AddZonedDateTime 1
// 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",
Expand All @@ -337,8 +338,6 @@ const expectedOpsForZonedRelativeTo = expected.concat([
// AddDuration → DifferenceZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → DifferenceZonedDateTime → DifferenceISODateTime
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateUntil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ let zdt = new Temporal.ZonedDateTime(
[epochInstant], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
],
[
// Behave normally in 4 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
// Behave normally in 3 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
Expand All @@ -74,8 +73,7 @@ zdt = new Temporal.ZonedDateTime(
[epochInstant], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
],
[
// Behave normally in 4 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
// Behave normally in 3 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
Expand Down Expand Up @@ -103,8 +101,7 @@ zdt = new Temporal.ZonedDateTime(
[new Temporal.Instant(-4n)], // Returned for NanosecondsToDays step 18.a, setting _oneDayFartherNs_
],
[
// Behave normally in 4 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
// Behave normally in 3 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
Expand Down
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 @@ -320,9 +320,10 @@ const expectedOpsForZonedRelativeTo = expected.concat([
"call options.relativeTo.timeZone.getPossibleInstantsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → AddZonedDateTime 1
// 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",
Expand All @@ -337,8 +338,6 @@ const expectedOpsForZonedRelativeTo = expected.concat([
// AddDuration → DifferenceZonedDateTime
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
// AddDuration → DifferenceZonedDateTime → DifferenceISODateTime
"get options.relativeTo.calendar.dateUntil",
"call options.relativeTo.calendar.dateUntil",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ let zdt = new Temporal.ZonedDateTime(
[epochInstant], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
],
[
// Behave normally in 4 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
// Behave normally in 3 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
Expand All @@ -73,8 +72,7 @@ zdt = new Temporal.ZonedDateTime(
[epochInstant], // Returned for NanosecondsToDays step 14, setting _intermediateNs_
],
[
// Behave normally in 4 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
// Behave normally in 3 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
Expand All @@ -101,8 +99,7 @@ zdt = new Temporal.ZonedDateTime(
[new Temporal.Instant(-4n)], // Returned for NanosecondsToDays step 18.a, setting _oneDayFartherNs_
],
[
// Behave normally in 4 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
// Behave normally in 3 calls made prior to NanosecondsToDays
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
TemporalHelpers.SUBSTITUTE_SKIP,
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 feb36c0

Please sign in to comment.