Skip to content

Commit

Permalink
Polyfill: Align MonthDay code with spec
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Aug 21, 2023
1 parent 8f4b219 commit 0669f4b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
3 changes: 0 additions & 3 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down

0 comments on commit 0669f4b

Please sign in to comment.