tc39 / proposal-temporal

Provides standard objects and functions for working with dates and times.
https://tc39.es/proposal-temporal/docs/
Other
3.19k stars 145 forks source link

Polyfill: Buddhist, Ethiopic-Amete-Alem, Indian, Islamic, and Persian calendar return non-undefind era #2899

Open anba opened 2 weeks ago

anba commented 2 weeks ago
Temporal.PlainDate.from({calendar: "buddhist", year: 1000, month: 1, day: 1}).era

returns "be" instead of undefined. Same applies for calendars ethioaa, indian, islamic (and variants), and persian.

Calendars chinese, dangi, and hebrew correctly return undefined for the era.

From CalendarDateEra:

It performs implementation-defined processing to find the era for the date corresponding to date in the context of the calendar represented by calendar and returns a lowercase String value representing that era, or undefined for calendars that do not have eras.

ptomato commented 5 days ago

This should be deferred to experts in those calendars, but the current era info in the polyfill comes from Intl.DateTimeFormat:

> new Intl.DateTimeFormat('en', {calendar: 'buddhist'}).format(Date.now())
'6/27/2567 BE'
anba commented 5 days ago

The era is possibly only displayed for English to disambiguate from the Gregorian calendar. When using locales which actually use the calendars, no era is displayed:

js> new Intl.DateTimeFormat("th", {calendar: "buddhist"}).format(Date.now())
"27/6/2567"
js> new Intl.DateTimeFormat("fa", {calendar: "persian", numberingSystem: "latn"}).format(Date.now())
"1403/4/7"
js> new Intl.DateTimeFormat("am", {calendar: "ethioaa"}).format(Date.now()) 
"20/10/7516"
ptomato commented 5 days ago

Oh. That explains it!