mirror of https://github.com/tc39/test262.git
Temporal: Avoid calendar operations when adding days-only duration to PlainDate
This commit is contained in:
parent
b5a5b283a3
commit
da3dd8802f
|
@ -119,14 +119,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([
|
||||
"get options.relativeTo.calendar.dateAdd", // 9.b
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.e
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.j
|
||||
"get options.relativeTo.calendar.dateUntil", // 9.m
|
||||
"call options.relativeTo.calendar.dateUntil", // 9.m
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.r
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get options.relativeTo.calendar.dateAdd", // 7.c
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.d
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.f
|
||||
"get options.relativeTo.calendar.dateUntil", // 7.n
|
||||
"call options.relativeTo.calendar.dateUntil", // 7.n
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.s
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.round(createOptionsObserver({ smallestUnit: "years", relativeTo: plainRelativeTo }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
@ -368,14 +367,13 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
|
|||
// NanosecondsToDays → AddDaysToZonedDateTime
|
||||
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||
"get options.relativeTo.calendar.dateAdd", // 9.b
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.e
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.j
|
||||
"get options.relativeTo.calendar.dateUntil", // 9.m
|
||||
"call options.relativeTo.calendar.dateUntil", // 9.m
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.r
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get options.relativeTo.calendar.dateAdd", // 7.c
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.d
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.f
|
||||
"get options.relativeTo.calendar.dateUntil", // 7.n
|
||||
"call options.relativeTo.calendar.dateUntil", // 7.n
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.s
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.round(createOptionsObserver({ smallestUnit: "years", relativeTo: zonedRelativeTo }));
|
||||
assert.compareArray(
|
||||
|
|
|
@ -102,14 +102,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expectedOpsForPlainRelativeTo.concat([
|
||||
"get options.relativeTo.calendar.dateAdd", // 9.b
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.e
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.j
|
||||
"get options.relativeTo.calendar.dateUntil", // 9.m
|
||||
"call options.relativeTo.calendar.dateUntil", // 9.m
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.r
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get options.relativeTo.calendar.dateAdd", // 7.c
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.d
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.f
|
||||
"get options.relativeTo.calendar.dateUntil", // 7.n
|
||||
"call options.relativeTo.calendar.dateUntil", // 7.n
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.s
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.total(createOptionsObserver({ unit: "years", relativeTo: plainRelativeTo }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with unit = years");
|
||||
|
@ -282,14 +281,13 @@ const expectedOpsForYearRoundingZoned = expectedOpsForZonedRelativeTo.concat([
|
|||
"call options.relativeTo.timeZone.getOffsetNanosecondsFor",
|
||||
"get options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||
"call options.relativeTo.timeZone.getPossibleInstantsFor",
|
||||
"get options.relativeTo.calendar.dateAdd", // 9.b
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.c
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.e
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.j
|
||||
"get options.relativeTo.calendar.dateUntil", // 9.m
|
||||
"call options.relativeTo.calendar.dateUntil", // 9.m
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.r
|
||||
"call options.relativeTo.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get options.relativeTo.calendar.dateAdd", // 7.c
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.d
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.f
|
||||
"get options.relativeTo.calendar.dateUntil", // 7.n
|
||||
"call options.relativeTo.calendar.dateUntil", // 7.n
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.s
|
||||
"call options.relativeTo.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.total(createOptionsObserver({ unit: "years", relativeTo: zonedRelativeTo }));
|
||||
assert.compareArray(
|
||||
|
|
|
@ -111,14 +111,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expected.concat([
|
||||
"get this.calendar.dateAdd", // 9.b
|
||||
"call this.calendar.dateAdd", // 9.c
|
||||
"call this.calendar.dateAdd", // 9.e
|
||||
"call this.calendar.dateAdd", // 9.j
|
||||
"get this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateAdd", // 9.r
|
||||
"call this.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get this.calendar.dateAdd", // 7.c
|
||||
"call this.calendar.dateAdd", // 7.d
|
||||
"call this.calendar.dateAdd", // 7.f
|
||||
"get this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateAdd", // 7.s
|
||||
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.since(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.tozoneddatetime
|
||||
description: >
|
||||
BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
|
||||
options value
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarDateAddUndefinedOptions();
|
||||
const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9);
|
||||
const instance = new Temporal.PlainDate(1970, 1, 1, calendar);
|
||||
instance.toZonedDateTime({ timeZone });
|
||||
assert.sameValue(calendar.dateAddCallCount, 1);
|
|
@ -111,14 +111,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expected.concat([
|
||||
"get this.calendar.dateAdd", // 9.b
|
||||
"call this.calendar.dateAdd", // 9.c
|
||||
"call this.calendar.dateAdd", // 9.e
|
||||
"call this.calendar.dateAdd", // 9.j
|
||||
"get this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateAdd", // 9.r
|
||||
"call this.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get this.calendar.dateAdd", // 7.c
|
||||
"call this.calendar.dateAdd", // 7.d
|
||||
"call this.calendar.dateAdd", // 7.f
|
||||
"get this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateAdd", // 7.s
|
||||
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.until(otherDatePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
|
|
@ -135,14 +135,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expected.concat([
|
||||
"get this.calendar.dateAdd", // 9.b
|
||||
"call this.calendar.dateAdd", // 9.c
|
||||
"call this.calendar.dateAdd", // 9.e
|
||||
"call this.calendar.dateAdd", // 9.j
|
||||
"get this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateAdd", // 9.r
|
||||
"call this.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get this.calendar.dateAdd", // 7.c
|
||||
"call this.calendar.dateAdd", // 7.d
|
||||
"call this.calendar.dateAdd", // 7.f
|
||||
"get this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateAdd", // 7.s
|
||||
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.tozoneddatetime
|
||||
description: >
|
||||
BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
|
||||
options value
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarDateAddUndefinedOptions();
|
||||
const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9);
|
||||
const instance = new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, 0, 0, 0, calendar);
|
||||
|
||||
["earlier", "compatible", "later"].forEach((disambiguation) => {
|
||||
calendar.dateAddCallCount = 0;
|
||||
|
||||
instance.toZonedDateTime(timeZone, { disambiguation });
|
||||
assert.sameValue(calendar.dateAddCallCount, 1, `calling with disambiguation ${disambiguation}`);
|
||||
});
|
|
@ -135,14 +135,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expected.concat([
|
||||
"get this.calendar.dateAdd", // 9.b
|
||||
"call this.calendar.dateAdd", // 9.c
|
||||
"call this.calendar.dateAdd", // 9.e
|
||||
"call this.calendar.dateAdd", // 9.j
|
||||
"get this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateAdd", // 9.r
|
||||
"call this.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get this.calendar.dateAdd", // 7.c
|
||||
"call this.calendar.dateAdd", // 7.d
|
||||
"call this.calendar.dateAdd", // 7.f
|
||||
"get this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateAdd", // 7.s
|
||||
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaintime.prototype.tozoneddatetime
|
||||
description: >
|
||||
BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
|
||||
options value
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarDateAddUndefinedOptions();
|
||||
const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9);
|
||||
const instance = new Temporal.PlainTime();
|
||||
instance.toZonedDateTime({ plainDate: new Temporal.PlainDate(1970, 1, 1, calendar), timeZone });
|
||||
assert.sameValue(calendar.dateAddCallCount, 1);
|
|
@ -15,4 +15,4 @@ assert.sameValue(calendar.dateAddCallCount, 1, "dateAdd called once with positiv
|
|||
|
||||
calendar.dateAddCallCount = 0;
|
||||
TemporalHelpers.assertPlainYearMonth(instance.add({days: -31}), 1983, 2, 'M02', "Adding -31 days to march in is8601 calendar")
|
||||
assert.sameValue(calendar.dateAddCallCount, 3, "dateAdd called 3 times with negative add");
|
||||
assert.sameValue(calendar.dateAddCallCount, 2, "dateAdd called 2 times with negative add");
|
||||
|
|
|
@ -124,14 +124,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expected.concat([
|
||||
"get this.calendar.dateAdd", // 9.b
|
||||
"call this.calendar.dateAdd", // 9.c
|
||||
"call this.calendar.dateAdd", // 9.e
|
||||
"call this.calendar.dateAdd", // 9.j
|
||||
"get this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateAdd", // 9.r
|
||||
"call this.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get this.calendar.dateAdd", // 7.c
|
||||
"call this.calendar.dateAdd", // 7.d
|
||||
"call this.calendar.dateAdd", // 7.f
|
||||
"get this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateAdd", // 7.s
|
||||
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.since(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
|
|
@ -33,7 +33,7 @@ class CustomCalendar extends Temporal.Calendar {
|
|||
dateAdd(date, duration, options) {
|
||||
const result = super.dateAdd(date, duration, options);
|
||||
dateAddCalls++;
|
||||
if (dateAddCalls == 3)
|
||||
if (dateAddCalls == 2)
|
||||
options.overflow = 'meatloaf';
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class CustomCalendar extends Temporal.Calendar {
|
|||
dateAdd(date, duration, options) {
|
||||
const result = super.dateAdd(date, duration, options);
|
||||
dateAddCalls++;
|
||||
if (dateAddCalls == 3)
|
||||
if (dateAddCalls == 2)
|
||||
options.overflow = 'meatloaf';
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ features: [Temporal]
|
|||
const calendar = TemporalHelpers.calendarDateAddPlainDateInstance();
|
||||
const instance = new Temporal.PlainYearMonth(1983, 3, calendar);
|
||||
TemporalHelpers.assertPlainYearMonth(instance.subtract({days: 31}), 1983, 2, 'M02', "Removing 31 days to march in is8601 calendar")
|
||||
assert.sameValue(calendar.dateAddCallCount, 3, "dateAdd called 3 times with positive subtract");
|
||||
assert.sameValue(calendar.dateAddCallCount, 2, "dateAdd called 2 times with positive subtract");
|
||||
|
||||
calendar.dateAddCallCount = 0;
|
||||
TemporalHelpers.assertPlainYearMonth(instance.subtract({days: -31}), 1983, 4, 'M04', "Removing -31 days to march in is8601 calendar")
|
||||
|
|
|
@ -15,7 +15,7 @@ class CustomCalendar extends Temporal.Calendar {
|
|||
}
|
||||
dateAdd(plainDate, duration, options) {
|
||||
++calls;
|
||||
if (calls == 3) {
|
||||
if (calls == 2) {
|
||||
TemporalHelpers.assertPlainDate(plainDate, 2000, 3, "M03", 31, "plainDate argument");
|
||||
TemporalHelpers.assertDuration(duration, 0, -10, 0, 0, 0, 0, 0, 0, 0, 0, "duration argument");
|
||||
assert.sameValue(typeof options, "object", "options argument: type");
|
||||
|
@ -28,4 +28,4 @@ class CustomCalendar extends Temporal.Calendar {
|
|||
const plainYearMonth = new Temporal.PlainYearMonth(2000, 3, new CustomCalendar());
|
||||
const result = plainYearMonth.subtract({ months: 10 });
|
||||
TemporalHelpers.assertPlainYearMonth(result, 1999, 5, "M05");
|
||||
assert.sameValue(calls, 3, "should have called dateAdd 3 times");
|
||||
assert.sameValue(calls, 2, "should have called dateAdd 2 times");
|
||||
|
|
|
@ -16,7 +16,7 @@ class CheckedAdd extends Temporal.Calendar {
|
|||
}
|
||||
dateAdd(date, duration, options, constructor) {
|
||||
this.called += 1;
|
||||
if (this.called == 3)
|
||||
if (this.called == 2)
|
||||
assert.notSameValue(options, undefined, "options not undefined");
|
||||
return super.dateAdd(date, duration, options, constructor);
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ const yearmonth = new Temporal.PlainYearMonth(2000, 3, calendar);
|
|||
const duration = { months: 1 };
|
||||
|
||||
yearmonth.subtract(duration, undefined);
|
||||
assert(calendar.called == 3);
|
||||
assert.sameValue(calendar.called, 2, "dateAdd should have been called twice");
|
||||
|
||||
calendar.called = 0;
|
||||
yearmonth.subtract(duration);
|
||||
assert(calendar.called == 3);
|
||||
assert.sameValue(calendar.called, 2, "dateAdd should have been called twice");
|
||||
|
|
|
@ -53,7 +53,6 @@ const expected = [
|
|||
"call this.calendar.dateFromFields",
|
||||
"get this.calendar.dateAdd",
|
||||
"call this.calendar.dateAdd",
|
||||
"call this.calendar.dateAdd",
|
||||
"get this.calendar.day",
|
||||
"call this.calendar.day",
|
||||
"get this.calendar.dateFromFields",
|
||||
|
|
|
@ -124,14 +124,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expected.concat([
|
||||
"get this.calendar.dateAdd", // 9.b
|
||||
"call this.calendar.dateAdd", // 9.c
|
||||
"call this.calendar.dateAdd", // 9.e
|
||||
"call this.calendar.dateAdd", // 9.j
|
||||
"get this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateAdd", // 9.r
|
||||
"call this.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get this.calendar.dateAdd", // 7.c
|
||||
"call this.calendar.dateAdd", // 7.d
|
||||
"call this.calendar.dateAdd", // 7.f
|
||||
"get this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateAdd", // 7.s
|
||||
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.until(otherYearMonthPropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.timezone.prototype.getinstantfor
|
||||
description: >
|
||||
BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
|
||||
options value
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarDateAddUndefinedOptions();
|
||||
const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9);
|
||||
const pdt = new Temporal.PlainDateTime(1970, 1, 1, 0, 0, 0, 0, 0, 0, calendar);
|
||||
|
||||
["earlier", "compatible", "later"].forEach((disambiguation) => {
|
||||
calendar.dateAddCallCount = 0;
|
||||
|
||||
timeZone.getInstantFor(pdt, { disambiguation });
|
||||
assert.sameValue(calendar.dateAddCallCount, 1, `calling with disambiguation ${disambiguation}`);
|
||||
});
|
|
@ -16,8 +16,7 @@ const earlier = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
|||
|
||||
// Basic difference with largestUnit larger than days.
|
||||
// The call comes from this path:
|
||||
// ZonedDateTime.since() -> DifferenceZonedDateTime -> AddZonedDateTime ->
|
||||
// BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||
// ZonedDateTime.since() -> DifferenceZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||
|
||||
const later1 = new Temporal.ZonedDateTime(1_213_200_000_000_000n, timeZone, calendar);
|
||||
later1.since(earlier, { largestUnit: "weeks" });
|
||||
|
@ -26,28 +25,12 @@ assert.sameValue(calendar.dateAddCallCount, 1, "basic difference with largestUni
|
|||
// Difference with rounding, with smallestUnit a calendar unit.
|
||||
// The calls come from these paths:
|
||||
// ZonedDateTime.since() ->
|
||||
// DifferenceZonedDateTime ->
|
||||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||
// DifferenceZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||
// RoundDuration ->
|
||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||
// MoveRelativeDate -> calendar.dateAdd()
|
||||
|
||||
calendar.dateAddCallCount = 0;
|
||||
|
||||
later1.since(earlier, { smallestUnit: "weeks" });
|
||||
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 path through
|
||||
// AdjustRoundedDurationDays -> AddDuration that's covered in the corresponding
|
||||
// test in until() only happens in one direction.)
|
||||
// The calls come from this path:
|
||||
// ZonedDateTime.since() -> AdjustRoundedDurationDays -> AddZonedDateTime ->
|
||||
// BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() (2x)
|
||||
|
||||
calendar.dateAddCallCount = 0;
|
||||
|
||||
const later2 = new Temporal.ZonedDateTime(86_399_999_999_999n, timeZone, calendar);
|
||||
later2.since(earlier, { largestUnit: "days", smallestUnit: "hours", roundingMode: "ceil" });
|
||||
assert.sameValue(calendar.dateAddCallCount, 2, "rounding difference with non-calendar smallestUnit and time difference longer than a calendar day");
|
||||
|
|
|
@ -208,14 +208,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expected.concat(expectedOpsForCalendarDifference, expectedOpsForCalendarRounding, [
|
||||
"get this.calendar.dateAdd", // 9.b
|
||||
"call this.calendar.dateAdd", // 9.c
|
||||
"call this.calendar.dateAdd", // 9.e
|
||||
"call this.calendar.dateAdd", // 9.j
|
||||
"get this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateAdd", // 9.r
|
||||
"call this.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get this.calendar.dateAdd", // 7.c
|
||||
"call this.calendar.dateAdd", // 7.d
|
||||
"call this.calendar.dateAdd", // 7.f
|
||||
"get this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateAdd", // 7.s
|
||||
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.since(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.startofday
|
||||
description: >
|
||||
BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
|
||||
options value
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarDateAddUndefinedOptions();
|
||||
const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9);
|
||||
const instance = new Temporal.ZonedDateTime(7200_000_000_000n, timeZone, calendar);
|
||||
instance.startOfDay();
|
||||
assert.sameValue(calendar.dateAddCallCount, 1);
|
|
@ -16,8 +16,7 @@ const earlier = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
|||
|
||||
// Basic difference with largestUnit larger than days.
|
||||
// The call comes from this path:
|
||||
// ZonedDateTime.until() -> DifferenceZonedDateTime -> AddZonedDateTime ->
|
||||
// BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||
// ZonedDateTime.until() -> DifferenceZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||
|
||||
const later1 = new Temporal.ZonedDateTime(1_213_200_000_000_000n, timeZone, calendar);
|
||||
earlier.until(later1, { largestUnit: "weeks" });
|
||||
|
@ -26,10 +25,9 @@ assert.sameValue(calendar.dateAddCallCount, 1, "basic difference with largestUni
|
|||
// Difference with rounding, with smallestUnit a calendar unit.
|
||||
// The calls come from these paths:
|
||||
// ZonedDateTime.until() ->
|
||||
// DifferenceZonedDateTime ->
|
||||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||
// DifferenceZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||
// RoundDuration ->
|
||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
|
||||
// MoveRelativeDate -> calendar.dateAdd()
|
||||
|
||||
calendar.dateAddCallCount = 0;
|
||||
|
|
|
@ -208,14 +208,13 @@ actual.splice(0); // clear
|
|||
|
||||
// code path through RoundDuration that rounds to the nearest year:
|
||||
const expectedOpsForYearRounding = expected.concat(expectedOpsForCalendarDifference, expectedOpsForCalendarRounding, [
|
||||
"get this.calendar.dateAdd", // 9.b
|
||||
"call this.calendar.dateAdd", // 9.c
|
||||
"call this.calendar.dateAdd", // 9.e
|
||||
"call this.calendar.dateAdd", // 9.j
|
||||
"get this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateUntil", // 9.m
|
||||
"call this.calendar.dateAdd", // 9.r
|
||||
"call this.calendar.dateAdd", // 9.w MoveRelativeDate
|
||||
"get this.calendar.dateAdd", // 7.c
|
||||
"call this.calendar.dateAdd", // 7.d
|
||||
"call this.calendar.dateAdd", // 7.f
|
||||
"get this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateUntil", // 7.n
|
||||
"call this.calendar.dateAdd", // 7.s
|
||||
"call this.calendar.dateAdd", // 7.x MoveRelativeDate
|
||||
]);
|
||||
instance.until(otherDateTimePropertyBag, createOptionsObserver({ smallestUnit: "years" }));
|
||||
assert.compareArray(actual, expectedOpsForYearRounding, "order of operations with smallestUnit = years");
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.withplaindate
|
||||
description: >
|
||||
BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
|
||||
options value
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarDateAddUndefinedOptions();
|
||||
const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9);
|
||||
const instance = new Temporal.ZonedDateTime(82800_000_000_000n, timeZone, calendar);
|
||||
instance.withPlainDate(new Temporal.PlainDate(1970, 1, 1, calendar));
|
||||
assert.sameValue(calendar.dateAddCallCount, 1);
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.withplaintime
|
||||
description: >
|
||||
BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
|
||||
options value
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarDateAddUndefinedOptions();
|
||||
const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9);
|
||||
const instance = new Temporal.ZonedDateTime(7200_000_000_000n, timeZone, calendar);
|
||||
instance.withPlainTime();
|
||||
assert.sameValue(calendar.dateAddCallCount, 1);
|
Loading…
Reference in New Issue