Skip to content

Temporal.Calendar.toLocaleString method #25

@ptomato

Description

@ptomato

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.DisplayNames and the precedent of toLocaleString().

Constraints / corner cases:

  • None known

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions