Skip to content

Commit

Permalink
Allow timeZone.getPossibleInstantsFor() to return an iterable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptomato committed Apr 16, 2021
1 parent 1670ebd commit e3e680b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ export const ES = ObjectAssign({}, ES2020, {
}

// "prefer" or "reject"
const possibleInstants = timeZone.getPossibleInstantsFor(dt);
const possibleInstants = ES.GetPossibleInstantsFor(timeZone, dt);
for (const candidate of possibleInstants) {
const candidateOffset = ES.GetOffsetNanosecondsFor(timeZone, candidate);
if (candidateOffset === offsetNs) return GetSlot(candidate, EPOCHNANOSECONDS);
Expand Down Expand Up @@ -2051,7 +2051,7 @@ export const ES = ObjectAssign({}, ES2020, {
GetPossibleInstantsFor: (timeZone, dateTime) => {
let getPossibleInstantsFor = ES.GetMethod(timeZone, 'getPossibleInstantsFor');
const possibleInstants = ES.Call(getPossibleInstantsFor, timeZone, [dateTime]);
const result = ES.CreateListFromArrayLike(possibleInstants, ['Object']);
const result = [...possibleInstants];
const numInstants = result.length;
for (let ix = 0; ix < numInstants; ix++) {
if (!ES.IsTemporalInstant(result[ix])) {
Expand Down Expand Up @@ -3844,6 +3844,7 @@ export const ES = ObjectAssign({}, ES2020, {
},
MoveRelativeDate: (calendar, relativeTo, duration) => {
const later = ES.CalendarDateAdd(calendar, relativeTo, duration, {});
relativeTo = ES.ToTemporalDateTime(relativeTo);
const days = ES.DaysUntil(relativeTo, later);
relativeTo = ES.CreateTemporalDateTime(
GetSlot(later, ISO_YEAR),
Expand Down
2 changes: 1 addition & 1 deletion spec/timezone.html
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ <h1>BuiltinTimeZoneGetInstantFor ( _timeZone_, _dateTime_, _disambiguation_ )</h
<h1>GetPossibleInstantsFor ( _timeZone_, _dateTime_ )</h1>
<emu-alg>
1. Let _possibleInstants_ be ? Invoke(_timeZone_, *"getPossibleInstantsFor"*, « _dateTime_ »).
1. Let _list_ be ? CreateListFromArrayLike(_possibleInstants_, « Object »).
1. Let _list_ be ? IterableToList(_possibleInstants_).
1. For each element _instant_ in _list_ in List order, do
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Return _list_.
Expand Down

0 comments on commit e3e680b

Please sign in to comment.