|
| 1 | +// Copyright (C) 2023 Igalia, S.L. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | + |
| 4 | +/*--- |
| 5 | +esid: sec-temporal.duration.prototype.subtract |
| 6 | +description: > |
| 7 | + Time zone's getPossibleInstantsFor is called with a PlainDateTime with the |
| 8 | + built-in ISO 8601 calendar |
| 9 | +features: [Temporal] |
| 10 | +info: | |
| 11 | + DisambiguatePossibleInstants: |
| 12 | + 2. Let _n_ be _possibleInstants_'s length. |
| 13 | + ... |
| 14 | + 5. Assert: _n_ = 0. |
| 15 | + ... |
| 16 | + 19. If _disambiguation_ is *"earlier"*, then |
| 17 | + ... |
| 18 | + c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). |
| 19 | + d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). |
| 20 | + ... |
| 21 | + 20. Assert: _disambiguation_ is *"compatible"* or *"later"*. |
| 22 | + ... |
| 23 | + 23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). |
| 24 | + 24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). |
| 25 | +---*/ |
| 26 | + |
| 27 | +class SkippedDateTime extends Temporal.TimeZone { |
| 28 | + constructor() { |
| 29 | + super("UTC"); |
| 30 | + this.calls = 0; |
| 31 | + } |
| 32 | + |
| 33 | + getPossibleInstantsFor(dateTime) { |
| 34 | + // Calls occur in pairs. For the first one return no possible instants so |
| 35 | + // that DisambiguatePossibleInstants will call it again |
| 36 | + if (this.calls++ % 2 == 0) { |
| 37 | + return []; |
| 38 | + } |
| 39 | + |
| 40 | + assert.sameValue( |
| 41 | + dateTime.getISOFields().calendar, |
| 42 | + "iso8601", |
| 43 | + "getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" |
| 44 | + ); |
| 45 | + return super.getPossibleInstantsFor(dateTime); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); |
| 50 | +const timeZone = new SkippedDateTime(); |
| 51 | +const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuiltinISOCalendar }; |
| 52 | + |
| 53 | +const instance = new Temporal.Duration(1, 0, 0, 1); |
| 54 | +instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); |
| 55 | + |
| 56 | +assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); |
0 commit comments