mirror of https://github.com/tc39/test262.git
Temporal: Precalculate PlainDateTime from ZonedDateTime in more places
This commit is contained in:
parent
3a57a424e0
commit
c04b417f66
|
@ -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",
|
||||
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
|
@ -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
|
||||
|
|
|
@ -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_
|
||||
]
|
||||
|
@ -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_
|
||||
]
|
||||
|
@ -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_
|
||||
]
|
||||
|
|
|
@ -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",
|
||||
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
@ -389,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
|
||||
|
|
|
@ -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_
|
||||
]
|
||||
|
@ -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_
|
||||
]
|
||||
|
@ -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_
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue