Skip to content

Commit

Permalink
Polyfill: Avoid ToString(calendar) when the calendar-id is unused
Browse files Browse the repository at this point in the history
Implements the normative change in the previous commit in the polyfill,
for the purpose of verifying test262 tests.
  • Loading branch information
ptomato committed Aug 3, 2022
1 parent cf586bc commit 6bd09e6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ export const ES = ObjectAssign({}, ES2020, {
if (z) return 'UTC';
return offset; // if !ianaName && !z then offset must be present
},
MaybeFormatCalendarAnnotation: (calendar, showCalendar) => {
if (showCalendar === 'never') return '';
return ES.FormatCalendarAnnotation(ES.ToString(calendar), showCalendar);
},
FormatCalendarAnnotation: (id, showCalendar) => {
if (showCalendar === 'never') return '';
if (showCalendar === 'auto' && id === 'iso8601') return '';
Expand Down Expand Up @@ -2024,8 +2028,7 @@ export const ES = ObjectAssign({}, ES2020, {
const year = ES.ISOYearString(GetSlot(date, ISO_YEAR));
const month = ES.ISODateTimePartString(GetSlot(date, ISO_MONTH));
const day = ES.ISODateTimePartString(GetSlot(date, ISO_DAY));
const calendarID = ES.ToString(GetSlot(date, CALENDAR));
const calendar = ES.FormatCalendarAnnotation(calendarID, showCalendar);
const calendar = ES.MaybeFormatCalendarAnnotation(GetSlot(date, CALENDAR), showCalendar);
return `${year}-${month}-${day}${calendar}`;
},
TemporalDateTimeToString: (dateTime, precision, showCalendar = 'auto', options = undefined) => {
Expand Down Expand Up @@ -2063,8 +2066,7 @@ export const ES = ObjectAssign({}, ES2020, {
hour = ES.ISODateTimePartString(hour);
minute = ES.ISODateTimePartString(minute);
const seconds = ES.FormatSecondsStringPart(second, millisecond, microsecond, nanosecond, precision);
const calendarID = ES.ToString(GetSlot(dateTime, CALENDAR));
const calendar = ES.FormatCalendarAnnotation(calendarID, showCalendar);
const calendar = ES.MaybeFormatCalendarAnnotation(GetSlot(dateTime, CALENDAR), showCalendar);
return `${year}-${month}-${day}T${hour}:${minute}${seconds}${calendar}`;
},
TemporalMonthDayToString: (monthDay, showCalendar = 'auto') => {
Expand Down Expand Up @@ -2134,8 +2136,7 @@ export const ES = ObjectAssign({}, ES2020, {
result += ES.FormatISOTimeZoneOffsetString(offsetNs);
}
if (showTimeZone !== 'never') result += `[${tz}]`;
const calendarID = ES.ToString(GetSlot(zdt, CALENDAR));
result += ES.FormatCalendarAnnotation(calendarID, showCalendar);
result += ES.MaybeFormatCalendarAnnotation(GetSlot(zdt, CALENDAR), showCalendar);
return result;
},

Expand Down

0 comments on commit 6bd09e6

Please sign in to comment.