From 0669f4bfb6cb9769ae46e23339476373dea2f555 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 21 Aug 2023 16:11:02 -0400 Subject: [PATCH] Polyfill: Align MonthDay code with spec --- polyfill/lib/calendar.mjs | 3 --- polyfill/lib/ecmascript.mjs | 8 ++------ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/polyfill/lib/calendar.mjs b/polyfill/lib/calendar.mjs index bafdcf8210..d01f7871d2 100644 --- a/polyfill/lib/calendar.mjs +++ b/polyfill/lib/calendar.mjs @@ -322,9 +322,6 @@ impl['iso8601'] = { monthDayFromFields(fields, options, calendarSlotValue) { fields = ES.PrepareTemporalFields(fields, ['day', 'month', 'monthCode', 'year'], ['day']); const overflow = ES.ToTemporalOverflow(options); - if (fields.month !== undefined && fields.year === undefined && fields.monthCode === undefined) { - throw new TypeError('either year or monthCode required with month'); - } const referenceISOYear = 1972; fields = resolveNonLunisolarMonth(fields); let { month, day, year } = fields; diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index c7f231517c..b823f3267a 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -1323,13 +1323,11 @@ export function ToTemporalMonthDay(item, options) { if (options !== undefined) options = SnapshotOwnProperties(GetOptionsObject(options), null); if (Type(item) === 'Object') { if (IsTemporalMonthDay(item)) return item; - let calendar, calendarAbsent; + let calendar; if (HasSlot(item, CALENDAR)) { calendar = GetSlot(item, CALENDAR); - calendarAbsent = false; } else { calendar = item.calendar; - calendarAbsent = calendar === undefined; if (calendar === undefined) calendar = 'iso8601'; calendar = ToTemporalCalendarSlotValue(calendar); } @@ -1338,9 +1336,6 @@ export function ToTemporalMonthDay(item, options) { // Callers who omit the calendar are not writing calendar-independent // code. In that case, `monthCode`/`year` can be omitted; `month` and // `day` are sufficient. Add a `year` to satisfy calendar validation. - if (calendarAbsent && fields.month !== undefined && fields.monthCode === undefined && fields.year === undefined) { - fields.year = 1972; - } return CalendarMonthDayFromFields(calendar, fields, options); } @@ -1351,6 +1346,7 @@ export function ToTemporalMonthDay(item, options) { ToTemporalOverflow(options); // validate and ignore if (referenceISOYear === undefined) { + if (calendar !== 'iso8601') throw new Error(`assertion failed: missing year with non-"iso8601" calendar identifier ${calendar}`); RejectISODate(1972, month, day); return CreateTemporalMonthDay(month, day, calendar); }