Skip to content

Commit 92569be

Browse files
Ms2ger12wrigja
andcommitted
Update PrepareTemporalFields to match the spec.
UPSTREAM_COMMIT=1e9ea70f694b2afc0f18a1faae64a8b3cf0604b6 Co-authored-by: James Wright <[email protected]>
1 parent 9375e03 commit 92569be

File tree

9 files changed

+199
-324
lines changed

9 files changed

+199
-324
lines changed

lib/calendar.ts

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -346,33 +346,23 @@ DefineIntrinsic('Temporal.Calendar.from', Calendar.from);
346346
impl['iso8601'] = {
347347
dateFromFields(fieldsParam, options, calendar) {
348348
const overflow = ES.ToTemporalOverflow(options);
349-
let fields = ES.PrepareTemporalFields(fieldsParam, [
350-
['day'],
351-
['month', undefined],
352-
['monthCode', undefined],
353-
['year']
354-
]);
349+
let fields = ES.PrepareTemporalFields(fieldsParam, ['day', 'month', 'monthCode', 'year'], ['year', 'day']);
355350
fields = resolveNonLunisolarMonth(fields);
356351
let { year, month, day } = fields;
357352
({ year, month, day } = ES.RegulateISODate(year, month, day, overflow));
358353
return ES.CreateTemporalDate(year, month, day, calendar);
359354
},
360355
yearMonthFromFields(fieldsParam, options, calendar) {
361356
const overflow = ES.ToTemporalOverflow(options);
362-
let fields = ES.PrepareTemporalFields(fieldsParam, [['month', undefined], ['monthCode', undefined], ['year']]);
357+
let fields = ES.PrepareTemporalFields(fieldsParam, ['month', 'monthCode', 'year'], ['year']);
363358
fields = resolveNonLunisolarMonth(fields);
364359
let { year, month } = fields;
365360
({ year, month } = ES.RegulateISOYearMonth(year, month, overflow));
366361
return ES.CreateTemporalYearMonth(year, month, calendar, /* referenceISODay = */ 1);
367362
},
368363
monthDayFromFields(fieldsParam, options, calendar) {
369364
const overflow = ES.ToTemporalOverflow(options);
370-
let fields = ES.PrepareTemporalFields(fieldsParam, [
371-
['day'],
372-
['month', undefined],
373-
['monthCode', undefined],
374-
['year', undefined]
375-
]);
365+
let fields = ES.PrepareTemporalFields(fieldsParam, ['day', 'month', 'monthCode', 'year'], ['day']);
376366
if (fields.month !== undefined && fields.year === undefined && fields.monthCode === undefined) {
377367
throw new TypeError('either year or monthCode required with month');
378368
}
@@ -1028,8 +1018,8 @@ abstract class HelperBase {
10281018
compareCalendarDates(date1Param: Partial<CalendarYMD>, date2Param: Partial<CalendarYMD>): 0 | 1 | -1 {
10291019
// `date1` and `date2` are already records. The calls below simply validate
10301020
// that all three required fields are present.
1031-
const date1 = ES.PrepareTemporalFields(date1Param, [['day'], ['month'], ['year']]);
1032-
const date2 = ES.PrepareTemporalFields(date2Param, [['day'], ['month'], ['year']]);
1021+
const date1 = ES.PrepareTemporalFields(date1Param, ['day', 'month', 'year'], ['day', 'month', 'year']);
1022+
const date2 = ES.PrepareTemporalFields(date2Param, ['day', 'month', 'year'], ['day', 'month', 'year']);
10331023
if (date1.year !== date2.year) return ES.ComparisonResult(date1.year - date2.year);
10341024
if (date1.month !== date2.month) return ES.ComparisonResult(date1.month - date2.month);
10351025
if (date1.day !== date2.day) return ES.ComparisonResult(date1.day - date2.day);
@@ -2299,14 +2289,11 @@ const nonIsoImpl: NonIsoImpl = {
22992289
const overflow = ES.ToTemporalOverflow(options);
23002290
const cache = new OneObjectCache();
23012291
// Intentionally alphabetical
2302-
const fields = ES.PrepareTemporalFields(fieldsParam, [
2303-
['day'],
2304-
['era', undefined],
2305-
['eraYear', undefined],
2306-
['month', undefined],
2307-
['monthCode', undefined],
2308-
['year', undefined]
2309-
]);
2292+
const fields = ES.PrepareTemporalFields(
2293+
fieldsParam,
2294+
['day', 'era', 'eraYear', 'month', 'monthCode', 'year'],
2295+
['day']
2296+
);
23102297
const { year, month, day } = this.helper.calendarToIsoDate(fields, overflow, cache);
23112298
const result = ES.CreateTemporalDate(year, month, day, calendar);
23122299
cache.setObject(result);
@@ -2316,13 +2303,7 @@ const nonIsoImpl: NonIsoImpl = {
23162303
const overflow = ES.ToTemporalOverflow(options);
23172304
const cache = new OneObjectCache();
23182305
// Intentionally alphabetical
2319-
const fields = ES.PrepareTemporalFields(fieldsParam, [
2320-
['era', undefined],
2321-
['eraYear', undefined],
2322-
['month', undefined],
2323-
['monthCode', undefined],
2324-
['year', undefined]
2325-
]);
2306+
const fields = ES.PrepareTemporalFields(fieldsParam, ['era', 'eraYear', 'month', 'monthCode', 'year'], []);
23262307
const { year, month, day } = this.helper.calendarToIsoDate({ ...fields, day: 1 }, overflow, cache);
23272308
const result = ES.CreateTemporalYearMonth(year, month, calendar, /* referenceISODay = */ day);
23282309
cache.setObject(result);
@@ -2339,14 +2320,11 @@ const nonIsoImpl: NonIsoImpl = {
23392320
// or `year` must be provided because `month` is ambiguous without a year or
23402321
// a code.
23412322
const cache = new OneObjectCache();
2342-
const fields = ES.PrepareTemporalFields(fieldsParam, [
2343-
['day'],
2344-
['era', undefined],
2345-
['eraYear', undefined],
2346-
['month', undefined],
2347-
['monthCode', undefined],
2348-
['year', undefined]
2349-
]);
2323+
const fields = ES.PrepareTemporalFields(
2324+
fieldsParam,
2325+
['day', 'era', 'eraYear', 'month', 'monthCode', 'year'],
2326+
['day']
2327+
);
23502328
const { year, month, day } = this.helper.monthDayFromFields(fields, overflow, cache);
23512329
// `year` is a reference year where this month/day exists in this calendar
23522330
const result = ES.CreateTemporalMonthDay(month, day, calendar, /* referenceISOYear = */ year);

0 commit comments

Comments
 (0)