Skip to content

Commit 64440b8

Browse files
committed
Allow calendar.fields() to return an iterable
The fields() methods of the built-in Temporal calendars will only ever return arrays, but this allows custom calendars to return an iterable (such as a Set.) See: #1427
1 parent a73b0fb commit 64440b8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ export namespace Temporal {
686686
| /** @deprecated */ 'day'
687687
>
688688
): Temporal.Duration;
689-
fields?(fields: Array<string>): Array<string>;
689+
fields?(fields: Array<string>): Iterable<string>;
690690
mergeFields?(fields: Record<string, unknown>, additionalFields: Record<string, unknown>): Record<string, unknown>;
691691
toString(): string;
692692
}
@@ -769,7 +769,7 @@ export namespace Temporal {
769769
| /** @deprecated */ 'day'
770770
>
771771
): Temporal.Duration;
772-
fields(fields: Array<string>): Array<string>;
772+
fields(fields: Array<string>): Iterable<string>;
773773
mergeFields(fields: Record<string, unknown>, additionalFields: Record<string, unknown>): Record<string, unknown>;
774774
toString(): string;
775775
}

lib/ecmascript.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,12 @@ export const ES = ObjectAssign({}, ES2020, {
17351735
CalendarFields: (calendar, fieldNames) => {
17361736
const fields = ES.GetMethod(calendar, 'fields');
17371737
if (fields !== undefined) fieldNames = ES.Call(fields, calendar, [fieldNames]);
1738-
return ES.CreateListFromArrayLike(fieldNames, ['String']);
1738+
const result = [];
1739+
for (const name of fieldNames) {
1740+
if (ES.Type(name) !== 'String') throw new TypeError('bad return from calendar.fields()');
1741+
ArrayPrototypePush.call(result, name);
1742+
}
1743+
return result;
17391744
},
17401745
CalendarMergeFields: (calendar, fields, additionalFields) => {
17411746
const mergeFields = ES.GetMethod(calendar, 'mergeFields');

0 commit comments

Comments
 (0)