Skip to content

Commit 9202f1f

Browse files
committed
Editorial: Remove individual AOs for each calendar field
These were all one line now, and should just call CalendarISOToDate. See: #2948
1 parent 8f90338 commit 9202f1f

14 files changed

+126
-419
lines changed

polyfill/lib/calendar.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -1992,4 +1992,3 @@ function calendarImpl(calendar) {
19921992
// Probably not what the intrinsics mechanism was intended for, but view this as
19931993
// an export of calendarImpl while avoiding circular dependencies
19941994
DefineIntrinsic('calendarImpl', calendarImpl);
1995-
DefineIntrinsic('calendarDateWeekOfYear', calendarDateWeekOfYear);

polyfill/lib/ecmascript.mjs

+10-63
Original file line numberDiff line numberDiff line change
@@ -1082,14 +1082,21 @@ export function TemporalObjectToFields(temporalObject) {
10821082
return ISODateToFields(calendar, isoDate, type);
10831083
}
10841084

1085+
export function calendarImplForObj(temporalObj) {
1086+
return GetIntrinsic('%calendarImpl%')(GetSlot(temporalObj, CALENDAR));
1087+
}
1088+
10851089
export function ISODateToFields(calendar, isoDate, type = 'date') {
10861090
const fields = ObjectCreate(null);
1087-
fields.monthCode = CalendarMonthCode(calendar, isoDate);
1091+
const calendarImpl = GetIntrinsic('%calendarImpl%')(calendar);
1092+
const calendarDate = calendarImpl.isoToDate(isoDate, { year: true, monthCode: true, day: true });
1093+
1094+
fields.monthCode = calendarDate.monthCode;
10881095
if (type === 'month-day' || type === 'date') {
1089-
fields.day = CalendarDay(calendar, isoDate);
1096+
fields.day = calendarDate.day;
10901097
}
10911098
if (type === 'year-month' || type === 'date') {
1092-
fields.year = CalendarYear(calendar, isoDate);
1099+
fields.year = calendarDate.year;
10931100
}
10941101
return fields;
10951102
}
@@ -1861,66 +1868,6 @@ export function CalendarDateUntil(calendar, isoDate, isoOtherDate, largestUnit)
18611868
return GetIntrinsic('%calendarImpl%')(calendar).dateUntil(isoDate, isoOtherDate, largestUnit);
18621869
}
18631870

1864-
export function CalendarYear(calendar, isoDate) {
1865-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { year: true }).year;
1866-
}
1867-
1868-
export function CalendarMonth(calendar, isoDate) {
1869-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { month: true }).month;
1870-
}
1871-
1872-
export function CalendarMonthCode(calendar, isoDate) {
1873-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { monthCode: true }).monthCode;
1874-
}
1875-
1876-
export function CalendarDay(calendar, isoDate) {
1877-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { day: true }).day;
1878-
}
1879-
1880-
export function CalendarEra(calendar, isoDate) {
1881-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { era: true }).era;
1882-
}
1883-
1884-
export function CalendarEraYear(calendar, isoDate) {
1885-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { eraYear: true }).eraYear;
1886-
}
1887-
1888-
export function CalendarDayOfWeek(calendar, isoDate) {
1889-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { dayOfWeek: true }).dayOfWeek;
1890-
}
1891-
1892-
export function CalendarDayOfYear(calendar, isoDate) {
1893-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { dayOfYear: true }).dayOfYear;
1894-
}
1895-
1896-
export function CalendarWeekOfYear(calendar, isoDate) {
1897-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { weekOfYear: true }).weekOfYear.week;
1898-
}
1899-
1900-
export function CalendarYearOfWeek(calendar, isoDate) {
1901-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { weekOfYear: true }).weekOfYear.year;
1902-
}
1903-
1904-
export function CalendarDaysInWeek(calendar, isoDate) {
1905-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { daysInWeek: true }).daysInWeek;
1906-
}
1907-
1908-
export function CalendarDaysInMonth(calendar, isoDate) {
1909-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { daysInMonth: true }).daysInMonth;
1910-
}
1911-
1912-
export function CalendarDaysInYear(calendar, isoDate) {
1913-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { daysInYear: true }).daysInYear;
1914-
}
1915-
1916-
export function CalendarMonthsInYear(calendar, isoDate) {
1917-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { monthsInYear: true }).monthsInYear;
1918-
}
1919-
1920-
export function CalendarInLeapYear(calendar, isoDate) {
1921-
return GetIntrinsic('%calendarImpl%')(calendar).isoToDate(isoDate, { inLeapYear: true }).inLeapYear;
1922-
}
1923-
19241871
export function ToTemporalCalendarIdentifier(calendarLike) {
19251872
if (Type(calendarLike) === 'Object') {
19261873
if (HasSlot(calendarLike, CALENDAR)) return GetSlot(calendarLike, CALENDAR);

polyfill/lib/plaindate.mjs

+15-15
Original file line numberDiff line numberDiff line change
@@ -34,77 +34,77 @@ export class PlainDate {
3434
get era() {
3535
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
3636
const isoDate = ES.TemporalObjectToISODateRecord(this);
37-
return ES.CalendarEra(GetSlot(this, CALENDAR), isoDate);
37+
return ES.calendarImplForObj(this).isoToDate(isoDate, { era: true }).era;
3838
}
3939
get eraYear() {
4040
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
4141
const isoDate = ES.TemporalObjectToISODateRecord(this);
42-
return ES.CalendarEraYear(GetSlot(this, CALENDAR), isoDate);
42+
return ES.calendarImplForObj(this).isoToDate(isoDate, { eraYear: true }).eraYear;
4343
}
4444
get year() {
4545
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
4646
const isoDate = ES.TemporalObjectToISODateRecord(this);
47-
return ES.CalendarYear(GetSlot(this, CALENDAR), isoDate);
47+
return ES.calendarImplForObj(this).isoToDate(isoDate, { year: true }).year;
4848
}
4949
get month() {
5050
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
5151
const isoDate = ES.TemporalObjectToISODateRecord(this);
52-
return ES.CalendarMonth(GetSlot(this, CALENDAR), isoDate);
52+
return ES.calendarImplForObj(this).isoToDate(isoDate, { month: true }).month;
5353
}
5454
get monthCode() {
5555
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
5656
const isoDate = ES.TemporalObjectToISODateRecord(this);
57-
return ES.CalendarMonthCode(GetSlot(this, CALENDAR), isoDate);
57+
return ES.calendarImplForObj(this).isoToDate(isoDate, { monthCode: true }).monthCode;
5858
}
5959
get day() {
6060
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
6161
const isoDate = ES.TemporalObjectToISODateRecord(this);
62-
return ES.CalendarDay(GetSlot(this, CALENDAR), isoDate);
62+
return ES.calendarImplForObj(this).isoToDate(isoDate, { day: true }).day;
6363
}
6464
get dayOfWeek() {
6565
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
6666
const isoDate = ES.TemporalObjectToISODateRecord(this);
67-
return ES.CalendarDayOfWeek(GetSlot(this, CALENDAR), isoDate);
67+
return ES.calendarImplForObj(this).isoToDate(isoDate, { dayOfWeek: true }).dayOfWeek;
6868
}
6969
get dayOfYear() {
7070
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
7171
const isoDate = ES.TemporalObjectToISODateRecord(this);
72-
return ES.CalendarDayOfYear(GetSlot(this, CALENDAR), isoDate);
72+
return ES.calendarImplForObj(this).isoToDate(isoDate, { dayOfYear: true }).dayOfYear;
7373
}
7474
get weekOfYear() {
7575
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
7676
const isoDate = ES.TemporalObjectToISODateRecord(this);
77-
return ES.CalendarWeekOfYear(GetSlot(this, CALENDAR), isoDate);
77+
return ES.calendarImplForObj(this).isoToDate(isoDate, { weekOfYear: true }).weekOfYear.week;
7878
}
7979
get yearOfWeek() {
8080
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
8181
const isoDate = ES.TemporalObjectToISODateRecord(this);
82-
return ES.CalendarYearOfWeek(GetSlot(this, CALENDAR), isoDate);
82+
return ES.calendarImplForObj(this).isoToDate(isoDate, { weekOfYear: true }).weekOfYear.year;
8383
}
8484
get daysInWeek() {
8585
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
8686
const isoDate = ES.TemporalObjectToISODateRecord(this);
87-
return ES.CalendarDaysInWeek(GetSlot(this, CALENDAR), isoDate);
87+
return ES.calendarImplForObj(this).isoToDate(isoDate, { daysInWeek: true }).daysInWeek;
8888
}
8989
get daysInMonth() {
9090
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
9191
const isoDate = ES.TemporalObjectToISODateRecord(this);
92-
return ES.CalendarDaysInMonth(GetSlot(this, CALENDAR), isoDate);
92+
return ES.calendarImplForObj(this).isoToDate(isoDate, { daysInMonth: true }).daysInMonth;
9393
}
9494
get daysInYear() {
9595
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
9696
const isoDate = ES.TemporalObjectToISODateRecord(this);
97-
return ES.CalendarDaysInYear(GetSlot(this, CALENDAR), isoDate);
97+
return ES.calendarImplForObj(this).isoToDate(isoDate, { daysInYear: true }).daysInYear;
9898
}
9999
get monthsInYear() {
100100
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
101101
const isoDate = ES.TemporalObjectToISODateRecord(this);
102-
return ES.CalendarMonthsInYear(GetSlot(this, CALENDAR), isoDate);
102+
return ES.calendarImplForObj(this).isoToDate(isoDate, { monthsInYear: true }).monthsInYear;
103103
}
104104
get inLeapYear() {
105105
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');
106106
const isoDate = ES.TemporalObjectToISODateRecord(this);
107-
return ES.CalendarInLeapYear(GetSlot(this, CALENDAR), isoDate);
107+
return ES.calendarImplForObj(this).isoToDate(isoDate, { inLeapYear: true }).inLeapYear;
108108
}
109109
with(temporalDateLike, options = undefined) {
110110
if (!ES.IsTemporalDate(this)) throw new TypeErrorCtor('invalid receiver');

polyfill/lib/plaindatetime.mjs

+15-15
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ export class PlainDateTime {
7171
get year() {
7272
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
7373
const isoDate = ES.TemporalObjectToISODateRecord(this);
74-
return ES.CalendarYear(GetSlot(this, CALENDAR), isoDate);
74+
return ES.calendarImplForObj(this).isoToDate(isoDate, { year: true }).year;
7575
}
7676
get month() {
7777
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
7878
const isoDate = ES.TemporalObjectToISODateRecord(this);
79-
return ES.CalendarMonth(GetSlot(this, CALENDAR), isoDate);
79+
return ES.calendarImplForObj(this).isoToDate(isoDate, { month: true }).month;
8080
}
8181
get monthCode() {
8282
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
8383
const isoDate = ES.TemporalObjectToISODateRecord(this);
84-
return ES.CalendarMonthCode(GetSlot(this, CALENDAR), isoDate);
84+
return ES.calendarImplForObj(this).isoToDate(isoDate, { monthCode: true }).monthCode;
8585
}
8686
get day() {
8787
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
8888
const isoDate = ES.TemporalObjectToISODateRecord(this);
89-
return ES.CalendarDay(GetSlot(this, CALENDAR), isoDate);
89+
return ES.calendarImplForObj(this).isoToDate(isoDate, { day: true }).day;
9090
}
9191
get hour() {
9292
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
@@ -115,57 +115,57 @@ export class PlainDateTime {
115115
get era() {
116116
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
117117
const isoDate = ES.TemporalObjectToISODateRecord(this);
118-
return ES.CalendarEra(GetSlot(this, CALENDAR), isoDate);
118+
return ES.calendarImplForObj(this).isoToDate(isoDate, { era: true }).era;
119119
}
120120
get eraYear() {
121121
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
122122
const isoDate = ES.TemporalObjectToISODateRecord(this);
123-
return ES.CalendarEraYear(GetSlot(this, CALENDAR), isoDate);
123+
return ES.calendarImplForObj(this).isoToDate(isoDate, { eraYear: true }).eraYear;
124124
}
125125
get dayOfWeek() {
126126
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
127127
const isoDate = ES.TemporalObjectToISODateRecord(this);
128-
return ES.CalendarDayOfWeek(GetSlot(this, CALENDAR), isoDate);
128+
return ES.calendarImplForObj(this).isoToDate(isoDate, { dayOfWeek: true }).dayOfWeek;
129129
}
130130
get dayOfYear() {
131131
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
132132
const isoDate = ES.TemporalObjectToISODateRecord(this);
133-
return ES.CalendarDayOfYear(GetSlot(this, CALENDAR), isoDate);
133+
return ES.calendarImplForObj(this).isoToDate(isoDate, { dayOfYear: true }).dayOfYear;
134134
}
135135
get weekOfYear() {
136136
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
137137
const isoDate = ES.TemporalObjectToISODateRecord(this);
138-
return ES.CalendarWeekOfYear(GetSlot(this, CALENDAR), isoDate);
138+
return ES.calendarImplForObj(this).isoToDate(isoDate, { weekOfYear: true }).weekOfYear.week;
139139
}
140140
get yearOfWeek() {
141141
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
142142
const isoDate = ES.TemporalObjectToISODateRecord(this);
143-
return ES.CalendarYearOfWeek(GetSlot(this, CALENDAR), isoDate);
143+
return ES.calendarImplForObj(this).isoToDate(isoDate, { weekOfYear: true }).weekOfYear.year;
144144
}
145145
get daysInWeek() {
146146
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
147147
const isoDate = ES.TemporalObjectToISODateRecord(this);
148-
return ES.CalendarDaysInWeek(GetSlot(this, CALENDAR), isoDate);
148+
return ES.calendarImplForObj(this).isoToDate(isoDate, { daysInWeek: true }).daysInWeek;
149149
}
150150
get daysInYear() {
151151
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
152152
const isoDate = ES.TemporalObjectToISODateRecord(this);
153-
return ES.CalendarDaysInYear(GetSlot(this, CALENDAR), isoDate);
153+
return ES.calendarImplForObj(this).isoToDate(isoDate, { daysInYear: true }).daysInYear;
154154
}
155155
get daysInMonth() {
156156
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
157157
const isoDate = ES.TemporalObjectToISODateRecord(this);
158-
return ES.CalendarDaysInMonth(GetSlot(this, CALENDAR), isoDate);
158+
return ES.calendarImplForObj(this).isoToDate(isoDate, { daysInMonth: true }).daysInMonth;
159159
}
160160
get monthsInYear() {
161161
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
162162
const isoDate = ES.TemporalObjectToISODateRecord(this);
163-
return ES.CalendarMonthsInYear(GetSlot(this, CALENDAR), isoDate);
163+
return ES.calendarImplForObj(this).isoToDate(isoDate, { monthsInYear: true }).monthsInYear;
164164
}
165165
get inLeapYear() {
166166
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
167167
const isoDate = ES.TemporalObjectToISODateRecord(this);
168-
return ES.CalendarInLeapYear(GetSlot(this, CALENDAR), isoDate);
168+
return ES.calendarImplForObj(this).isoToDate(isoDate, { inLeapYear: true }).inLeapYear;
169169
}
170170
with(temporalDateTimeLike, options = undefined) {
171171
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');

polyfill/lib/plainmonthday.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export class PlainMonthDay {
1919
get monthCode() {
2020
if (!ES.IsTemporalMonthDay(this)) throw new TypeErrorCtor('invalid receiver');
2121
const isoDate = ES.TemporalObjectToISODateRecord(this);
22-
return ES.CalendarMonthCode(GetSlot(this, CALENDAR), isoDate);
22+
return ES.calendarImplForObj(this).isoToDate(isoDate, { monthCode: true }).monthCode;
2323
}
2424
get day() {
2525
if (!ES.IsTemporalMonthDay(this)) throw new TypeErrorCtor('invalid receiver');
2626
const isoDate = ES.TemporalObjectToISODateRecord(this);
27-
return ES.CalendarDay(GetSlot(this, CALENDAR), isoDate);
27+
return ES.calendarImplForObj(this).isoToDate(isoDate, { day: true }).day;
2828
}
2929
get calendarId() {
3030
if (!ES.IsTemporalMonthDay(this)) throw new TypeErrorCtor('invalid receiver');

polyfill/lib/plainyearmonth.mjs

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ export class PlainYearMonth {
1818
get year() {
1919
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
2020
const isoDate = ES.TemporalObjectToISODateRecord(this);
21-
return ES.CalendarYear(GetSlot(this, CALENDAR), isoDate);
21+
return ES.calendarImplForObj(this).isoToDate(isoDate, { year: true }).year;
2222
}
2323
get month() {
2424
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
2525
const isoDate = ES.TemporalObjectToISODateRecord(this);
26-
return ES.CalendarMonth(GetSlot(this, CALENDAR), isoDate);
26+
return ES.calendarImplForObj(this).isoToDate(isoDate, { month: true }).month;
2727
}
2828
get monthCode() {
2929
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
3030
const isoDate = ES.TemporalObjectToISODateRecord(this);
31-
return ES.CalendarMonthCode(GetSlot(this, CALENDAR), isoDate);
31+
return ES.calendarImplForObj(this).isoToDate(isoDate, { monthCode: true }).monthCode;
3232
}
3333
get calendarId() {
3434
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
@@ -37,32 +37,32 @@ export class PlainYearMonth {
3737
get era() {
3838
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
3939
const isoDate = ES.TemporalObjectToISODateRecord(this);
40-
return ES.CalendarEra(GetSlot(this, CALENDAR), isoDate);
40+
return ES.calendarImplForObj(this).isoToDate(isoDate, { era: true }).era;
4141
}
4242
get eraYear() {
4343
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
4444
const isoDate = ES.TemporalObjectToISODateRecord(this);
45-
return ES.CalendarEraYear(GetSlot(this, CALENDAR), isoDate);
45+
return ES.calendarImplForObj(this).isoToDate(isoDate, { eraYear: true }).eraYear;
4646
}
4747
get daysInMonth() {
4848
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
4949
const isoDate = ES.TemporalObjectToISODateRecord(this);
50-
return ES.CalendarDaysInMonth(GetSlot(this, CALENDAR), isoDate);
50+
return ES.calendarImplForObj(this).isoToDate(isoDate, { daysInMonth: true }).daysInMonth;
5151
}
5252
get daysInYear() {
5353
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
5454
const isoDate = ES.TemporalObjectToISODateRecord(this);
55-
return ES.CalendarDaysInYear(GetSlot(this, CALENDAR), isoDate);
55+
return ES.calendarImplForObj(this).isoToDate(isoDate, { daysInYear: true }).daysInYear;
5656
}
5757
get monthsInYear() {
5858
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
5959
const isoDate = ES.TemporalObjectToISODateRecord(this);
60-
return ES.CalendarMonthsInYear(GetSlot(this, CALENDAR), isoDate);
60+
return ES.calendarImplForObj(this).isoToDate(isoDate, { monthsInYear: true }).monthsInYear;
6161
}
6262
get inLeapYear() {
6363
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');
6464
const isoDate = ES.TemporalObjectToISODateRecord(this);
65-
return ES.CalendarInLeapYear(GetSlot(this, CALENDAR), isoDate);
65+
return ES.calendarImplForObj(this).isoToDate(isoDate, { inLeapYear: true }).inLeapYear;
6666
}
6767
with(temporalYearMonthLike, options = undefined) {
6868
if (!ES.IsTemporalYearMonth(this)) throw new TypeErrorCtor('invalid receiver');

0 commit comments

Comments
 (0)