mirror of
https://github.com/tc39/test262.git
synced 2025-11-17 20:29:48 +01:00
In the AO DisambiguatePossibleInstants, a PlainDateTime instance is passed to user code. This instance should have the built-in ISO 8601 calendar. Here are some tests that ensure it does. See tc39/proposal-temporal#2671.
59 lines
2.1 KiB
JavaScript
59 lines
2.1 KiB
JavaScript
// 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.zoneddatetime.prototype.compare
|
|
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");
|
|
const timeZone1 = new SkippedDateTime();
|
|
const arg1 = { year: 2000, month: 5, day: 2, timeZone: timeZone1, calendar: nonBuiltinISOCalendar };
|
|
const timeZone2 = new SkippedDateTime();
|
|
const arg2 = { year: 2000, month: 5, day: 2, timeZone: timeZone2, calendar: nonBuiltinISOCalendar };
|
|
|
|
Temporal.ZonedDateTime.compare(arg1, arg2);
|
|
|
|
assert.sameValue(timeZone1.calls, 2, "getPossibleInstantsFor should have been called 2 times on first time zone");
|
|
assert.sameValue(timeZone2.calls, 2, "getPossibleInstantsFor should have been called 2 times on second time zone");
|