Skip to content

Commit 0835da5

Browse files
committed
Allow timeZone.getPossibleInstantsFor() to return an iterable
The getPossibleInstantsFor() methods of the built-in Temporal time zones will only ever return arrays, but this allows custom time zones to return an iterable (such as a Set.) See: #1427
1 parent 0947c07 commit 0835da5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/ecmascript.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ export const ES = ObjectAssign({}, ES2020, {
14961496
}
14971497

14981498
// "prefer" or "reject"
1499-
const possibleInstants = timeZone.getPossibleInstantsFor(dt);
1499+
const possibleInstants = ES.GetPossibleInstantsFor(timeZone, dt);
15001500
for (const candidate of possibleInstants) {
15011501
const candidateOffset = ES.GetOffsetNanosecondsFor(timeZone, candidate);
15021502
if (candidateOffset === offsetNs) return GetSlot(candidate, EPOCHNANOSECONDS);
@@ -2052,12 +2052,12 @@ export const ES = ObjectAssign({}, ES2020, {
20522052
GetPossibleInstantsFor: (timeZone, dateTime) => {
20532053
let getPossibleInstantsFor = ES.GetMethod(timeZone, 'getPossibleInstantsFor');
20542054
const possibleInstants = ES.Call(getPossibleInstantsFor, timeZone, [dateTime]);
2055-
const result = ES.CreateListFromArrayLike(possibleInstants, ['Object']);
2056-
const numInstants = result.length;
2057-
for (let ix = 0; ix < numInstants; ix++) {
2058-
if (!ES.IsTemporalInstant(result[ix])) {
2055+
const result = [];
2056+
for (const instant of possibleInstants) {
2057+
if (!ES.IsTemporalInstant(instant)) {
20592058
throw new TypeError('bad return from getPossibleInstantsFor');
20602059
}
2060+
ArrayPrototypePush.call(result, instant);
20612061
}
20622062
return result;
20632063
},

0 commit comments

Comments
 (0)