From da3dd8802f8a0dd8eac34e8cd8b37d2363c32f29 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 8 Mar 2023 17:57:48 -0800 Subject: [PATCH] Temporal: Avoid calendar operations when adding days-only duration to PlainDate --- .../prototype/round/order-of-operations.js | 30 +++++++++---------- .../prototype/total/order-of-operations.js | 30 +++++++++---------- .../prototype/since/order-of-operations.js | 15 +++++----- ...r-dateadd-called-with-options-undefined.js | 17 ----------- .../prototype/until/order-of-operations.js | 15 +++++----- .../prototype/since/order-of-operations.js | 15 +++++----- ...r-dateadd-called-with-options-undefined.js | 22 -------------- .../prototype/until/order-of-operations.js | 15 +++++----- ...r-dateadd-called-with-options-undefined.js | 17 ----------- ...-dateadd-called-with-plaindate-instance.js | 2 +- .../prototype/since/order-of-operations.js | 15 +++++----- .../calendar-arguments-extra-options.js | 2 +- .../prototype/subtract/calendar-arguments.js | 2 +- ...-dateadd-called-with-plaindate-instance.js | 2 +- .../prototype/subtract/calendar-dateadd.js | 4 +-- .../prototype/subtract/options-undefined.js | 6 ++-- .../prototype/subtract/order-of-operations.js | 1 - .../prototype/until/order-of-operations.js | 15 +++++----- ...r-dateadd-called-with-options-undefined.js | 22 -------------- ...r-dateadd-called-with-options-undefined.js | 23 ++------------ .../prototype/since/order-of-operations.js | 15 +++++----- ...r-dateadd-called-with-options-undefined.js | 17 ----------- ...r-dateadd-called-with-options-undefined.js | 8 ++--- .../prototype/until/order-of-operations.js | 15 +++++----- ...r-dateadd-called-with-options-undefined.js | 17 ----------- ...r-dateadd-called-with-options-undefined.js | 17 ----------- 26 files changed, 99 insertions(+), 260 deletions(-) delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js delete mode 100644 test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js delete mode 100644 test/built-ins/Temporal/TimeZone/prototype/getInstantFor/calendar-dateadd-called-with-options-undefined.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/startOfDay/calendar-dateadd-called-with-options-undefined.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/calendar-dateadd-called-with-options-undefined.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/calendar-dateadd-called-with-options-undefined.js diff --git a/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js b/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js index ab96bc4996..6b09b4ae15 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js @@ -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( diff --git a/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js b/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js index ea4402460b..81e69c34aa 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js @@ -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( diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/since/order-of-operations.js index cccbaf230c..19753ea868 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/order-of-operations.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 04afc0acd6..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/order-of-operations.js b/test/built-ins/Temporal/PlainDate/prototype/until/order-of-operations.js index 602f08936e..92b61a07d3 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/order-of-operations.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/order-of-operations.js index e1b7deb4e6..f7c54c7e77 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/order-of-operations.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 367dd55144..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -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}`); -}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/order-of-operations.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/order-of-operations.js index 43ea0733d9..cf681eaea9 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/order-of-operations.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 6c10625d57..0000000000 --- a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/calendar-dateadd-called-with-plaindate-instance.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/calendar-dateadd-called-with-plaindate-instance.js index a8dd88ce07..288ce158d4 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/calendar-dateadd-called-with-plaindate-instance.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/calendar-dateadd-called-with-plaindate-instance.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/order-of-operations.js index 735225b469..f870702b96 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/order-of-operations.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-arguments-extra-options.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-arguments-extra-options.js index 46384397d7..931a89a047 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-arguments-extra-options.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-arguments-extra-options.js @@ -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; } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-arguments.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-arguments.js index 122e29ae28..c8608a67d8 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-arguments.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-arguments.js @@ -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; } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd-called-with-plaindate-instance.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd-called-with-plaindate-instance.js index 037d83a78a..8d0fe87863 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd-called-with-plaindate-instance.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd-called-with-plaindate-instance.js @@ -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") diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd.js index 0e39c359ff..5219b3ab51 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/calendar-dateadd.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-undefined.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-undefined.js index c1e7fc7f1c..b0cf9bd9d4 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-undefined.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/options-undefined.js @@ -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"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/order-of-operations.js index d92ed783eb..18f4650af2 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/order-of-operations.js @@ -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", diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/order-of-operations.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/order-of-operations.js index 3e6864fc4b..fb9046c254 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/order-of-operations.js @@ -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"); diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 4a8f43ced0..0000000000 --- a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -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}`); -}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/calendar-dateadd-called-with-options-undefined.js index c8fcfc96cc..ea8e220b1e 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/calendar-dateadd-called-with-options-undefined.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/calendar-dateadd-called-with-options-undefined.js @@ -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"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js index 4e7725463d..666e26b787 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/order-of-operations.js @@ -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"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/startOfDay/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/ZonedDateTime/prototype/startOfDay/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 0fb6b7e5a7..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/startOfDay/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/calendar-dateadd-called-with-options-undefined.js index 84a263ec23..82cdb9e137 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/calendar-dateadd-called-with-options-undefined.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/calendar-dateadd-called-with-options-undefined.js @@ -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; diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js index c29daf3248..71dec65c3c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/order-of-operations.js @@ -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"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 8b22fa81dc..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 387aeacb84..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -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);