summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Temporal/TimeZone/prototype/getInstantFor/getpossibleinstantsfor-called-with-iso8601-calendar.js
blob: b78f801c25615f6ae4b28a56f17b69548f60c89c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.timezone.prototype.getinstantfor
description: >
  Time zone's getPossibleInstantsFor is called with a PlainDateTime with the
  built-in ISO 8601 calendar
features: [Temporal]
info: |
  DisambiguatePossibleInstants:
  2. Let _n_ be _possibleInstants_'s length.
  ...
  5. Assert: _n_ = 0.
  ...
  19. If _disambiguation_ is *"earlier"*, then
    ...
    c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*).
    d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_).
    ...
  20. Assert: _disambiguation_ is *"compatible"* or *"later"*.
  ...
  23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*).
  24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_).
---*/

class SkippedDateTime extends Temporal.TimeZone {
  constructor() {
    super("UTC");
    this.calls = 0;
  }

  getPossibleInstantsFor(dateTime) {
    // Calls occur in pairs. For the first one return no possible instants so
    // that DisambiguatePossibleInstants will call it again
    if (this.calls++ % 2 == 0) {
      return [];
    }

    assert.sameValue(
      dateTime.getISOFields().calendar,
      "iso8601",
      "getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar"
    );
    return super.getPossibleInstantsFor(dateTime);
  }
}

const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601");

for (const disambiguation of ["earlier", "later", "compatible"]) {
  const timeZone = new SkippedDateTime();
  timeZone.getInstantFor(new Temporal.PlainDateTime(2000, 3, 4, 12, 34, 56, 0, 0, 0, nonBuiltinISOCalendar), { disambiguation });

  assert.sameValue(timeZone.calls, 2, "getPossibleInstantsFor should have been called 2 times");
}

reportCompare(0, 0);