@@ -346,6 +346,14 @@ function ParseTemporalTimeZone(stringIdent: string) {
346
346
return offset as string ; // if !ianaName && !z then offset must be present
347
347
}
348
348
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
+
349
357
function FormatCalendarAnnotation ( id : string , showCalendar : Temporal . ShowCalendarOption [ 'calendarName' ] ) {
350
358
if ( showCalendar === 'never' ) return '' ;
351
359
if ( showCalendar === 'auto' && id === 'iso8601' ) return '' ;
@@ -2655,8 +2663,7 @@ export function TemporalDateToString(
2655
2663
const year = ISOYearString ( GetSlot ( date , ISO_YEAR ) ) ;
2656
2664
const month = ISODateTimePartString ( GetSlot ( date , ISO_MONTH ) ) ;
2657
2665
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 ) ;
2660
2667
return `${ year } -${ month } -${ day } ${ calendar } ` ;
2661
2668
}
2662
2669
@@ -2700,8 +2707,7 @@ export function TemporalDateTimeToString(
2700
2707
const hourString = ISODateTimePartString ( hour ) ;
2701
2708
const minuteString = ISODateTimePartString ( minute ) ;
2702
2709
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 ) ;
2705
2711
return `${ yearString } -${ monthString } -${ dayString } T${ hourString } :${ minuteString } ${ secondsString } ${ calendar } ` ;
2706
2712
}
2707
2713
@@ -2780,8 +2786,7 @@ export function TemporalZonedDateTimeToString(
2780
2786
result += FormatISOTimeZoneOffsetString ( offsetNs ) ;
2781
2787
}
2782
2788
if ( showTimeZone !== 'never' ) result += `[${ tz } ]` ;
2783
- const calendarID = ToString ( GetSlot ( zdt , CALENDAR ) ) ;
2784
- result += FormatCalendarAnnotation ( calendarID , showCalendar ) ;
2789
+ result += MaybeFormatCalendarAnnotation ( GetSlot ( zdt , CALENDAR ) , showCalendar ) ;
2785
2790
return result ;
2786
2791
}
2787
2792
0 commit comments