mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Temporal: Fast-path AddDaysToZonedDateTime in AddZonedDateTime
This commit is contained in:
parent
8040379076
commit
b5a5b283a3
@ -266,21 +266,6 @@ const expectedOpsForZonedRelativeTo = expected.concat([
|
|||||||
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const expectedOpsForZonedCalendarCompare = [
|
|
||||||
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
|
||||||
// AddZonedDateTime on first argument
|
|
||||||
"get options.relativeTo.calendar.dateAdd",
|
|
||||||
"call options.relativeTo.calendar.dateAdd",
|
|
||||||
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
|
||||||
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
|
||||||
// AddZonedDateTime on second argument
|
|
||||||
"get options.relativeTo.calendar.dateAdd",
|
|
||||||
"call options.relativeTo.calendar.dateAdd",
|
|
||||||
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
|
||||||
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
|
||||||
];
|
|
||||||
|
|
||||||
const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
|
const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
|
||||||
year: 2001,
|
year: 2001,
|
||||||
month: 5,
|
month: 5,
|
||||||
@ -305,7 +290,16 @@ Temporal.Duration.compare(
|
|||||||
);
|
);
|
||||||
assert.compareArray(
|
assert.compareArray(
|
||||||
actual,
|
actual,
|
||||||
expectedOpsForZonedRelativeTo.concat(expectedOpsForZonedCalendarCompare),
|
expectedOpsForZonedRelativeTo.concat([
|
||||||
|
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||||
|
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||||
|
// AddDaysToZonedDateTime on first argument
|
||||||
|
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
|
// AddDaysToZonedDateTime on second argument
|
||||||
|
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
|
]),
|
||||||
"order of operations with ZonedDateTime relativeTo and no calendar units except days"
|
"order of operations with ZonedDateTime relativeTo and no calendar units except days"
|
||||||
);
|
);
|
||||||
actual.splice(0); // clear
|
actual.splice(0); // clear
|
||||||
@ -331,7 +325,20 @@ Temporal.Duration.compare(
|
|||||||
);
|
);
|
||||||
assert.compareArray(
|
assert.compareArray(
|
||||||
actual,
|
actual,
|
||||||
expectedOpsForZonedRelativeTo.concat(expectedOpsForZonedCalendarCompare),
|
expectedOpsForZonedRelativeTo.concat([
|
||||||
|
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||||
|
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||||
|
// AddZonedDateTime on first argument
|
||||||
|
"get options.relativeTo.calendar.dateAdd",
|
||||||
|
"call options.relativeTo.calendar.dateAdd",
|
||||||
|
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
|
// AddZonedDateTime on second argument
|
||||||
|
"get options.relativeTo.calendar.dateAdd",
|
||||||
|
"call options.relativeTo.calendar.dateAdd",
|
||||||
|
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
|
]),
|
||||||
"order of operations with ZonedDateTime relativeTo and calendar units"
|
"order of operations with ZonedDateTime relativeTo and calendar units"
|
||||||
);
|
);
|
||||||
actual.splice(0); // clear
|
actual.splice(0); // clear
|
||||||
|
@ -40,11 +40,12 @@ features: [Temporal]
|
|||||||
var one = Temporal.Duration.from({
|
var one = Temporal.Duration.from({
|
||||||
days: Number.MAX_SAFE_INTEGER,
|
days: Number.MAX_SAFE_INTEGER,
|
||||||
weeks: 3,
|
weeks: 3,
|
||||||
|
years: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
var two = Temporal.Duration.from({
|
var two = Temporal.Duration.from({
|
||||||
days: Number.MAX_SAFE_INTEGER + 3,
|
days: Number.MAX_SAFE_INTEGER + 3,
|
||||||
weeks: 0,
|
years: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
var cal = new class extends Temporal.Calendar {
|
var cal = new class extends Temporal.Calendar {
|
||||||
|
@ -18,15 +18,14 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
|||||||
// The calls come from these paths:
|
// The calls come from these paths:
|
||||||
// Duration.round() ->
|
// Duration.round() ->
|
||||||
// RoundDuration ->
|
// RoundDuration ->
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||||
// BalanceDuration ->
|
// MoveRelativeDate -> calendar.dateAdd()
|
||||||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
|
||||||
// BalanceDurationRelative ->
|
// BalanceDurationRelative ->
|
||||||
// MoveRelativeDate -> calendar.dateAdd() (2x)
|
// MoveRelativeDate -> calendar.dateAdd() (2x)
|
||||||
// calendar.dateAdd()
|
// calendar.dateAdd()
|
||||||
|
|
||||||
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
||||||
instance1.round({ smallestUnit: "days", relativeTo });
|
instance1.round({ smallestUnit: "weeks", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 5, "rounding with calendar smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 5, "rounding with calendar smallestUnit");
|
||||||
|
|
||||||
// Rounding with a non-default largestUnit to cover the path in
|
// Rounding with a non-default largestUnit to cover the path in
|
||||||
@ -40,7 +39,7 @@ assert.sameValue(calendar.dateAddCallCount, 5, "rounding with calendar smallestU
|
|||||||
// MoveRelativeDate -> calendar.dateAdd() (5x)
|
// MoveRelativeDate -> calendar.dateAdd() (5x)
|
||||||
// BalanceDurationRelative
|
// BalanceDurationRelative
|
||||||
// MoveRelativeDate -> calendar.dateAdd()
|
// MoveRelativeDate -> calendar.dateAdd()
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||||
|
|
||||||
calendar.dateAddCallCount = 0;
|
calendar.dateAddCallCount = 0;
|
||||||
|
|
||||||
@ -48,18 +47,17 @@ const instance2 = new Temporal.Duration(0, 1, 1, 1);
|
|||||||
instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo });
|
instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 8, "rounding with non-default largestUnit and calendar smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 8, "rounding with non-default largestUnit and calendar smallestUnit");
|
||||||
|
|
||||||
// Rounding with smallestUnit a non-calendar unit, and having the resulting time
|
// Rounding with smallestUnit days only.
|
||||||
// difference be longer than a calendar day, covering the paths that go through
|
|
||||||
// AdjustRoundedDurationDays.
|
|
||||||
// The calls come from these paths:
|
// The calls come from these paths:
|
||||||
// Duration.round() ->
|
// Duration.round() ->
|
||||||
// AdjustRoundedDurationDays -> AddDuration ->
|
// RoundDuration ->
|
||||||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||||
// BalanceDuration ->
|
// BalanceDurationRelative ->
|
||||||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// MoveRelativeDate -> calendar.dateAdd() (2x)
|
||||||
|
// calendar.dateAdd()
|
||||||
|
|
||||||
calendar.dateAddCallCount = 0;
|
calendar.dateAddCallCount = 0;
|
||||||
|
|
||||||
const instance3 = new Temporal.Duration(0, 0, 0, 0, 23, 59, 59, 999, 999, 999);
|
const instance3 = new Temporal.Duration(1, 1, 1, 1, 1);
|
||||||
instance3.round({ largestUnit: "days", smallestUnit: "hours", roundingMode: "ceil", relativeTo });
|
instance3.round({ smallestUnit: "days", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 2, "rounding with time difference exceeding calendar day");
|
assert.sameValue(calendar.dateAddCallCount, 4, "rounding with days smallestUnit");
|
||||||
|
@ -21,12 +21,10 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
|||||||
// UnbalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd() (3x)
|
// UnbalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd() (3x)
|
||||||
// BalanceDuration ->
|
// BalanceDuration ->
|
||||||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||||
// RoundDuration ->
|
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
|
||||||
|
|
||||||
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
||||||
instance1.total({ unit: "days", relativeTo });
|
instance1.total({ unit: "days", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 5, "converting larger calendar units down");
|
assert.sameValue(calendar.dateAddCallCount, 3, "converting larger calendar units down");
|
||||||
|
|
||||||
// Total of a calendar unit where smaller calendar units have to be converted
|
// Total of a calendar unit where smaller calendar units have to be converted
|
||||||
// up, to cover the path that goes through MoveRelativeZonedDateTime
|
// up, to cover the path that goes through MoveRelativeZonedDateTime
|
||||||
@ -36,11 +34,10 @@ assert.sameValue(calendar.dateAddCallCount, 5, "converting larger calendar units
|
|||||||
// BalanceDuration ->
|
// BalanceDuration ->
|
||||||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||||
// RoundDuration ->
|
// RoundDuration ->
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
|
||||||
// MoveRelativeDate -> calendar.dateAdd()
|
// MoveRelativeDate -> calendar.dateAdd()
|
||||||
|
|
||||||
calendar.dateAddCallCount = 0;
|
calendar.dateAddCallCount = 0;
|
||||||
|
|
||||||
const instance2 = new Temporal.Duration(0, 0, 1, 1);
|
const instance2 = new Temporal.Duration(0, 0, 1, 1);
|
||||||
instance2.total({ unit: "weeks", relativeTo });
|
instance2.total({ unit: "weeks", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 4, "converting smaller calendar units up");
|
assert.sameValue(calendar.dateAddCallCount, 3, "converting smaller calendar units up");
|
||||||
|
@ -277,12 +277,10 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
|
|||||||
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
], [
|
], [
|
||||||
// code path through RoundDuration that rounds to the nearest year:
|
// code path through RoundDuration that rounds to the nearest year:
|
||||||
// MoveRelativeZonedDateTime → AddZonedDateTime
|
// MoveRelativeZonedDateTime → AddDaysToZonedDateTime
|
||||||
"get options.relativeTo.timeZone.getOffsetNanosecondsFor", // 5. GetPlainDateTimeFor
|
"get options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||||
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||||
"get options.relativeTo.calendar.dateAdd", // 8.
|
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
"call options.relativeTo.calendar.dateAdd",
|
|
||||||
"get options.relativeTo.timeZone.getPossibleInstantsFor", // 10. GetInstantFor
|
|
||||||
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||||
"get options.relativeTo.calendar.dateAdd", // 9.b
|
"get options.relativeTo.calendar.dateAdd", // 9.b
|
||||||
"call options.relativeTo.calendar.dateAdd", // 9.c
|
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||||
|
@ -44,10 +44,10 @@ assert.sameValue(calendar.dateAddCallCount, 3, "rounding difference with calenda
|
|||||||
// test in until() only happens in one direction.)
|
// test in until() only happens in one direction.)
|
||||||
// The calls come from this path:
|
// The calls come from this path:
|
||||||
// ZonedDateTime.since() -> AdjustRoundedDurationDays -> AddZonedDateTime ->
|
// ZonedDateTime.since() -> AdjustRoundedDurationDays -> AddZonedDateTime ->
|
||||||
// BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() (3x)
|
// BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() (2x)
|
||||||
|
|
||||||
calendar.dateAddCallCount = 0;
|
calendar.dateAddCallCount = 0;
|
||||||
|
|
||||||
const later2 = new Temporal.ZonedDateTime(86_399_999_999_999n, timeZone, calendar);
|
const later2 = new Temporal.ZonedDateTime(86_399_999_999_999n, timeZone, calendar);
|
||||||
later2.since(earlier, { largestUnit: "days", smallestUnit: "hours", roundingMode: "ceil" });
|
later2.since(earlier, { largestUnit: "days", smallestUnit: "hours", roundingMode: "ceil" });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 3, "rounding difference with non-calendar smallestUnit and time difference longer than a calendar day");
|
assert.sameValue(calendar.dateAddCallCount, 2, "rounding difference with non-calendar smallestUnit and time difference longer than a calendar day");
|
||||||
|
@ -36,15 +36,3 @@ calendar.dateAddCallCount = 0;
|
|||||||
|
|
||||||
earlier.until(later1, { smallestUnit: "weeks" });
|
earlier.until(later1, { smallestUnit: "weeks" });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 3, "rounding difference with calendar smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 3, "rounding difference with calendar smallestUnit");
|
||||||
|
|
||||||
// Difference with rounding, with smallestUnit a non-calendar unit, and having
|
|
||||||
// the resulting time difference be longer than a calendar day, covering the
|
|
||||||
// paths that go through AdjustRoundedDurationDays.
|
|
||||||
// The call comes from this path:
|
|
||||||
// ZonedDateTime.until() -> AdjustRoundedDurationDays -> AddZonedDateTime ->
|
|
||||||
// BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
|
||||||
calendar.dateAddCallCount = 0;
|
|
||||||
|
|
||||||
const later2 = new Temporal.ZonedDateTime(86_399_999_999_999n, timeZone, calendar);
|
|
||||||
earlier.until(later2, { largestUnit: "days", smallestUnit: "hours", roundingMode: "ceil" });
|
|
||||||
assert.sameValue(calendar.dateAddCallCount, 1, "rounding difference with non-calendar smallestUnit and time difference longer than a calendar day");
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user