forked from tc39/proposal-temporal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These files test that calendar.dateAdd() is always called with undefined as the options parameter from paths going through BuiltinTimeZoneGetInstantFor. Some tests must be skipped as they depend on tc39#1685 which will make calendar.dateAdd() be called with undefined as the options parameter from other operations as well. (If tc39#1685 does not go through, then these tests will need to be rewritten.) Includes fixes to the testing polyfill, fixing a few places where a Temporal object was created internally using the ISO calendar instead of the calendar passed to it.
- Loading branch information
Showing
21 changed files
with
631 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
polyfill/test/Duration/constructor/compare/calendar-dateadd-called-with-options-undefined.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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.duration.compare | ||
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 relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar); | ||
|
||
const duration1 = new Temporal.Duration(0, 0, 1); | ||
const duration2 = new Temporal.Duration(0, 0, 1); | ||
Temporal.Duration.compare(duration1, duration2, { relativeTo }); | ||
assert.sameValue(calendar.dateAddCallCount, 4); | ||
// one call in CalculateOffsetShift for each duration argument, plus one in | ||
// UnbalanceDurationRelative for each duration argument |
17 changes: 17 additions & 0 deletions
17
polyfill/test/Duration/prototype/add/calendar-dateadd-called-with-options-undefined.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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.duration.prototype.add | ||
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.Duration(1, 1, 1, 1); | ||
instance.add(instance, { relativeTo: new Temporal.ZonedDateTime(0n, timeZone, calendar) }); | ||
assert.sameValue(calendar.dateAddCallCount, 5); |
73 changes: 73 additions & 0 deletions
73
polyfill/test/Duration/prototype/round/calendar-dateadd-called-with-options-undefined.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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.duration.prototype.round | ||
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 relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar); | ||
|
||
// Rounding with smallestUnit a calendar unit. | ||
// The calls come from these paths: | ||
// Duration.round() -> | ||
// RoundDuration -> | ||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
// NanosecondsToDays -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
// BalanceDurationRelative -> | ||
// MoveRelativeDate -> calendar.dateAdd() (2x) | ||
// calendar.dateAdd() | ||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
// BalanceDuration -> | ||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
// NanosecondsToDays -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() (2x) | ||
|
||
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1); | ||
instance1.round({ smallestUnit: "days", relativeTo }); | ||
assert.sameValue(calendar.dateAddCallCount, 9, "rounding with calendar smallestUnit"); | ||
|
||
// Rounding with a non-default largestUnit to cover the path in | ||
// UnbalanceDurationRelative where larger units are converted into smaller | ||
// units; and with a smallestUnit larger than days to cover the path in | ||
// RoundDuration where days are converted into larger units. | ||
// The calls come from these paths: | ||
// Duration.round() -> | ||
// UnbalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd() | ||
// RoundDuration -> | ||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
// MoveRelativeDate -> calendar.dateAdd() (5x) | ||
// BalanceDurationRelative | ||
// MoveRelativeDate -> calendar.dateAdd() | ||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
|
||
calendar.dateAddCallCount = 0; | ||
|
||
const instance2 = new Temporal.Duration(0, 1, 1, 1); | ||
instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo }); | ||
assert.sameValue(calendar.dateAddCallCount, 9, "rounding with non-default largestUnit and calendar smallestUnit"); | ||
|
||
// 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 calls come from these paths: | ||
// Duration.round() -> | ||
// AdjustRoundedDurationDays -> | ||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
// AddDuration -> | ||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
// NanosecondsToDays -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() (2x) | ||
// BalanceDuration -> | ||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() | ||
// NanosecondsToDays -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() (2x) | ||
|
||
calendar.dateAddCallCount = 0; | ||
|
||
const instance3 = new Temporal.Duration(0, 0, 0, 0, 23, 59, 59, 999, 999, 999); | ||
instance3.round({ largestUnit: "days", smallestUnit: "hours", roundingMode: "ceil", relativeTo }); | ||
assert.sameValue(calendar.dateAddCallCount, 7, "rounding with time difference exceeding calendar day"); |
17 changes: 17 additions & 0 deletions
17
polyfill/test/Duration/prototype/subtract/calendar-dateadd-called-with-options-undefined.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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.duration.prototype.subtract | ||
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.Duration(1, 1, 1, 1); | ||
instance.subtract(new Temporal.Duration(-1, -1, -1, -1), { relativeTo: new Temporal.ZonedDateTime(0n, timeZone, calendar) }); | ||
assert.sameValue(calendar.dateAddCallCount, 5); |
Oops, something went wrong.