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.
6 esid: sec-temporal.zoneddatetime.prototype.since
8 BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the
10 includes: [temporalHelpers.js]
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()
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");