1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
2 // Copyright (C) 2024 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 esid: sec-temporal.duration.prototype.total
7 Rounding the resulting duration takes the time zone's UTC offset shifts
9 includes: [temporalHelpers.js]
13 const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
15 // Based on a test case by Adam Shaw
18 // Date part of duration lands on skipped DST hour, causing disambiguation
19 const duration = new Temporal.Duration(0, 1, 0, 15, 12);
20 const relativeTo = new Temporal.ZonedDateTime(
21 950868000_000_000_000n /* = 2000-02-18T10Z */,
22 timeZone); /* = 2000-02-18T02-08 in local time */
24 assert.sameValue(duration.total({ unit: "months", relativeTo }), 1.5,
25 "1 month 15 days 12 hours should be exactly 1.5 months");
29 // Month-only part of duration lands on skipped DST hour, should not cause
31 const duration = new Temporal.Duration(0, 1, 0, 15);
32 const relativeTo = new Temporal.ZonedDateTime(
33 951991200_000_000_000n /* = 2000-03-02T10Z */,
34 timeZone); /* = 2000-03-02T02-08 in local time */
36 assert.sameValue(duration.total({ unit: "months", relativeTo }), 1.5,
37 "1 month 15 days should be exactly 1.5 months");