Skip to content

Commit db3c033

Browse files
Ms2ger12wrigja
authored andcommitted
Move IsBuiltinCalendar to ecmascript.ts.
UPSTREAM_COMMIT=bfaabda0bd64ef02413e84ad5f926002e47a1f50
1 parent 0bc0415 commit db3c033

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

lib/calendar.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class Calendar implements Temporal.Calendar {
127127
}
128128

129129
const id = ES.ToString(idParam);
130-
if (!IsBuiltinCalendar(id)) throw new RangeError(`invalid calendar identifier ${id}`);
130+
if (!ES.IsBuiltinCalendar(id)) throw new RangeError(`invalid calendar identifier ${id}`);
131131
CreateSlots(this);
132132
SetSlot(this, CALENDAR_ID, id);
133133

@@ -2540,9 +2540,3 @@ for (const Helper of [
25402540
// calendars. The `helper` property contains per-calendar logic.
25412541
impl[helper.id] = { ...nonIsoImpl, helper };
25422542
}
2543-
2544-
const BUILTIN_CALENDAR_IDS = Object.keys(impl) as BuiltinCalendarId[];
2545-
2546-
export function IsBuiltinCalendar(id: string): id is BuiltinCalendarId {
2547-
return ArrayIncludes.call(BUILTIN_CALENDAR_IDS, id);
2548-
}

lib/ecmascript.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const ArrayIncludes = Array.prototype.includes;
12
const ArrayPrototypePush = Array.prototype.push;
23
const IntlDateTimeFormat = globalThis.Intl.DateTimeFormat;
34
const MathMin = Math.min;
@@ -36,7 +37,8 @@ import type {
3637
DurationParams,
3738
PlainDateTimeParams,
3839
PlainYearMonthParams,
39-
FieldRecord
40+
FieldRecord,
41+
BuiltinCalendarId
4042
} from './internaltypes';
4143
import { GetIntrinsic } from './intrinsicclass';
4244
import {
@@ -73,7 +75,6 @@ import {
7375
MICROSECONDS,
7476
NANOSECONDS
7577
} from './slots';
76-
import { IsBuiltinCalendar } from './calendar';
7778

7879
export const ZERO = JSBI.BigInt(0);
7980
const ONE = JSBI.BigInt(1);
@@ -93,6 +94,28 @@ const ABOUT_TEN_YEARS_NANOS = JSBI.multiply(DAY_NANOS, JSBI.BigInt(366 * 10));
9394
const ABOUT_ONE_YEAR_NANOS = JSBI.multiply(DAY_NANOS, JSBI.BigInt(366 * 1));
9495
const TWO_WEEKS_NANOS = JSBI.multiply(DAY_NANOS, JSBI.BigInt(2 * 7));
9596

97+
const BUILTIN_CALENDAR_IDS = [
98+
'iso8601',
99+
'hebrew',
100+
'islamic',
101+
'islamic-umalqura',
102+
'islamic-tbla',
103+
'islamic-civil',
104+
'islamic-rgsa',
105+
'islamicc',
106+
'persian',
107+
'ethiopic',
108+
'ethioaa',
109+
'coptic',
110+
'chinese',
111+
'dangi',
112+
'roc',
113+
'indian',
114+
'buddhist',
115+
'japanese',
116+
'gregory'
117+
];
118+
96119
function IsInteger(value: unknown): value is number {
97120
if (typeof value !== 'number' || !NumberIsFinite(value)) return false;
98121
const abs = MathAbs(value);
@@ -5293,6 +5316,10 @@ function GetNumberOption<P extends string, T extends Partial<Record<P, unknown>>
52935316
return MathFloor(value);
52945317
}
52955318

5319+
export function IsBuiltinCalendar(id: string): id is BuiltinCalendarId {
5320+
return ArrayIncludes.call(BUILTIN_CALENDAR_IDS, id);
5321+
}
5322+
52965323
const OFFSET = new RegExp(`^${PARSE.offset.source}$`);
52975324

52985325
function bisect(

0 commit comments

Comments
 (0)