Backed out 3 changesets (bug 1892041) for causing failures on async-module-does-not...
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / ZonedDateTime / prototype / since / calendar-dateadd-called-with-options-undefined.js
blob7a5367bf294ccd155546793495362be5e534cf96
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
2 // Copyright (C) 2021 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-temporal.zoneddatetime.prototype.since
7 description: >
8     BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
9     options value
10 includes: [temporalHelpers.js]
11 features: [Temporal]
12 ---*/
14 const calendar = TemporalHelpers.calendarDateAddUndefinedOptions();
15 const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9);
16 const earlier = new Temporal.ZonedDateTime(0n, timeZone, calendar);
18 // Basic difference with largestUnit larger than days.
19 // The call comes from this path:
20 // ZonedDateTime.since() -> DifferenceZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
22 const later1 = new Temporal.ZonedDateTime(1_213_200_000_000_000n, timeZone, calendar);
23 later1.since(earlier, { largestUnit: "weeks" });
24 assert.sameValue(calendar.dateAddCallCount, 1, "basic difference with largestUnit >days");
26 // Difference with rounding, with smallestUnit a calendar unit.
27 // The calls come from these paths:
28 // ZonedDateTime.since() ->
29 //   DifferenceZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
30 //   RoundDuration ->
31 //     MoveRelativeZonedDateTime -> AddZonedDateTime -> calendar.dateAdd()
32 //     MoveRelativeDate -> calendar.dateAdd()
33 //   BalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd()
35 calendar.dateAddCallCount = 0;
37 later1.since(earlier, { smallestUnit: "weeks" });
38 assert.sameValue(calendar.dateAddCallCount, 4, "rounding difference with calendar smallestUnit");
40 reportCompare(0, 0);