Skip to content

Commit ddba8e6

Browse files
committed
Polyfill: Make gregory calendar return undefined week numbers
This is currently unspecified behaviour, and is to be specified later in tc39/proposal-intl-era-monthcode#15 Closes: #3096 UPSTREAM_COMMIT=2e156ecb102cd4e1c93b21b26f2611832f6499de
1 parent a79c6a1 commit ddba8e6

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

lib/calendar.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ function arrayFromSet<T>(src: Set<T>): T[] {
2020
}
2121

2222
function calendarDateWeekOfYear(id: BuiltinCalendarId, isoDate: ISODate): { week: number; year: number } | undefined {
23-
// Supports only Gregorian and ISO8601 calendar; can be updated to add support for other calendars.
23+
// Supports only ISO8601 calendar; can be updated to add support for other calendars.
2424
// Returns undefined for calendars without a well-defined week calendar system.
2525
// eslint-disable-next-line max-len
2626
// Also see: https://github.com/unicode-org/icu/blob/ab72ab1d4a3c3f9beeb7d92b0c7817ca93dfdb04/icu4c/source/i18n/calendar.cpp#L1606
27-
if (id !== 'gregory' && id !== 'iso8601') return undefined;
27+
if (id !== 'iso8601') return undefined;
2828
const calendar = impl[id];
2929
let yow = isoDate.year;
3030
const { dayOfWeek, dayOfYear, daysInYear } = calendar.isoToDate(isoDate, {
@@ -34,8 +34,8 @@ function calendarDateWeekOfYear(id: BuiltinCalendarId, isoDate: ISODate): { week
3434
});
3535
const fdow = calendar.getFirstDayOfWeek();
3636
const mdow = calendar.getMinimalDaysInFirstWeek();
37-
ES.uncheckedAssertNarrowedType<number>(fdow, 'guaranteed to exist for iso8601/gregory');
38-
ES.uncheckedAssertNarrowedType<number>(mdow, 'guaranteed to exist for iso8601/gregory');
37+
ES.uncheckedAssertNarrowedType<number>(fdow, 'guaranteed to exist for iso8601');
38+
ES.uncheckedAssertNarrowedType<number>(mdow, 'guaranteed to exist for iso8601');
3939

4040
// For both the input date and the first day of its calendar year, calculate the day of week
4141
// relative to first day of week in the relevant calendar (e.g., in iso8601, relative to Monday).
@@ -1972,12 +1972,6 @@ class GregoryHelper extends SameMonthDayAsGregorianBaseHelper {
19721972
if (era === 'a') era = 'gregory';
19731973
return { era, eraYear } as T;
19741974
}
1975-
override getFirstDayOfWeek() {
1976-
return 1;
1977-
}
1978-
override getMinimalDaysInFirstWeek() {
1979-
return 1;
1980-
}
19811975
}
19821976

19831977
// NOTE: Only the 5 modern eras (Meiji and later) are included. For dates

0 commit comments

Comments
 (0)