Skip to content

Commit cb0c200

Browse files
ptomato12wrigja
authored andcommitted
Avoid ToString(calendar) when the calendar-id is unused
Implements the normative change in the previous commit in the polyfill, for the purpose of verifying test262 tests. UPSTREAM_COMMIT=6bd09e6d0ac70d6f4a262e771e9e59da3fee7910
1 parent 0d2d60e commit cb0c200

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/ecmascript.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ function ParseTemporalTimeZone(stringIdent: string) {
346346
return offset as string; // if !ianaName && !z then offset must be present
347347
}
348348

349+
function MaybeFormatCalendarAnnotation(
350+
calendar: Temporal.CalendarProtocol,
351+
showCalendar: Temporal.ShowCalendarOption['calendarName']
352+
): string {
353+
if (showCalendar === 'never') return '';
354+
return FormatCalendarAnnotation(ToString(calendar), showCalendar);
355+
}
356+
349357
function FormatCalendarAnnotation(id: string, showCalendar: Temporal.ShowCalendarOption['calendarName']) {
350358
if (showCalendar === 'never') return '';
351359
if (showCalendar === 'auto' && id === 'iso8601') return '';
@@ -2655,8 +2663,7 @@ export function TemporalDateToString(
26552663
const year = ISOYearString(GetSlot(date, ISO_YEAR));
26562664
const month = ISODateTimePartString(GetSlot(date, ISO_MONTH));
26572665
const day = ISODateTimePartString(GetSlot(date, ISO_DAY));
2658-
const calendarID = ToString(GetSlot(date, CALENDAR));
2659-
const calendar = FormatCalendarAnnotation(calendarID, showCalendar);
2666+
const calendar = MaybeFormatCalendarAnnotation(GetSlot(date, CALENDAR), showCalendar);
26602667
return `${year}-${month}-${day}${calendar}`;
26612668
}
26622669

@@ -2700,8 +2707,7 @@ export function TemporalDateTimeToString(
27002707
const hourString = ISODateTimePartString(hour);
27012708
const minuteString = ISODateTimePartString(minute);
27022709
const secondsString = FormatSecondsStringPart(second, millisecond, microsecond, nanosecond, precision);
2703-
const calendarID = ToString(GetSlot(dateTime, CALENDAR));
2704-
const calendar = FormatCalendarAnnotation(calendarID, showCalendar);
2710+
const calendar = MaybeFormatCalendarAnnotation(GetSlot(dateTime, CALENDAR), showCalendar);
27052711
return `${yearString}-${monthString}-${dayString}T${hourString}:${minuteString}${secondsString}${calendar}`;
27062712
}
27072713

@@ -2780,8 +2786,7 @@ export function TemporalZonedDateTimeToString(
27802786
result += FormatISOTimeZoneOffsetString(offsetNs);
27812787
}
27822788
if (showTimeZone !== 'never') result += `[${tz}]`;
2783-
const calendarID = ToString(GetSlot(zdt, CALENDAR));
2784-
result += FormatCalendarAnnotation(calendarID, showCalendar);
2789+
result += MaybeFormatCalendarAnnotation(GetSlot(zdt, CALENDAR), showCalendar);
27852790
return result;
27862791
}
27872792

0 commit comments

Comments
 (0)