-
Notifications
You must be signed in to change notification settings - Fork 1
Description
From @FrankYFTang at tc39/proposal-temporal#2367:
Currently, Temporal.Calendar only has toString ( ) method but no toLocaleString ( ) method as other Temporal objects ( PlainDate, PlainTime, PlainDateTime, PlainYearMonth, PlainMonthDay, ZonedDateTime, Instant, Duration)
Temporal spec should consider adding toLocaleString for Temporal.Calendar
Intl.DisplayNames in ECMA402 already support "calendar", Temporal.Calendar.prototype.toLocaleString() could just delegate to Intl.DisplayNames in the same way as how it delegate to Intl.DateTimeFormat in the current spec.
Advantages:
A more intuitive way to get the localized name of a calendar:
calendar.toLocaleString('en-CA', { style: 'short' });vs
const name = new Intl.DisplayNames('en-CA', { type: 'calendar', style: 'short' });
name.of(calendar);Concerns:
Currently calling calendar.toLocaleString() resolves to Object.prototype.toLocaleString() which calls calendar.toString(). So existing behaviour could change. I believe that changing the output of toLocaleString() would be web-compatible, though.
Prior art:
- Prior art is actually within JS already:
Intl.DisplayNamesand the precedent oftoLocaleString().
Constraints / corner cases:
- None known