Skip to content

Commit

Permalink
fixup! Non-ISO calendar implementations use classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
12wrigja committed Dec 5, 2022
1 parent 9457858 commit 9350ee7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ interface CalendarImpl {
mergeFields(fields: Record<string, unknown>, additionalFields: Record<string, unknown>): Record<string, unknown>;
}

type CalendarImplementations = {
[k in BuiltinCalendarId]: CalendarImpl;
};

/**
* Implementations for each calendar. Non-ISO calendars have an extra `helper`
* property that provides additional per-calendar logic.
* Implementations for each calendar.
* Registration for each of these calendars happens throughout this file. The ISO and non-ISO calendars are registered
* separately - look for 'iso8601' for the ISO calendar registration, and all non-ISO calendar registrations happens
* at the bottom of the file.
*/
const impl = {} as {
iso8601: CalendarImpl;
} & {
[id in Exclude<BuiltinCalendarId, 'iso8601'>]: CalendarImpl;
};
const impl: CalendarImplementations = {} as unknown as CalendarImplementations;

/**
* Thin wrapper around the implementation of each built-in calendar. This
Expand Down Expand Up @@ -2498,7 +2500,7 @@ for (const Helper of [
IslamicCcHelper
]) {
const helper = new Helper();
// Clone the singleton non-ISO implementation that's the same for all
// calendars. The `helper` property contains per-calendar logic.
// Construct a new NonIsoCalendar instance with the given Helper implementation that contains
// per-calendar logic.
impl[helper.id] = new NonIsoCalendar(helper);
}

0 comments on commit 9350ee7

Please sign in to comment.