tc39 / proposal-intl-displaynames-v2

Intl DisplayNames API V2
https://tc39.es/proposal-intl-displaynames-v2/
MIT License
23 stars 3 forks source link

Getting month and weekday names is easier with Temporal #4

Closed sffc closed 3 years ago

sffc commented 4 years ago

The code examples in the motivation section in the README are saying that getting month names with legacy Date is hard. I think that Temporal solves this problem.

function getMonthNames(locale, year, calendar) {
    let result = [];
    for (let yearMonth = Temporal.YearMonth.from({ year, month: 1, calendar });
            yearMonth.year === year;
            yearMonth = yearMonth.plus({ months: 1 })) {
        result.push(yearMonth.toLocaleString(locale, { month: "long" }));
    }
}
justingrant commented 3 years ago

Regardless of whether temporalObject.toLocaleString() or dateTimeFormat.formatToParts(temporalObject) is used to fetch the name, do any of the problems noted in the README still apply? From looking at the README, it seems like the problems listed there are focused on legacy Date's inability to handle time zones and calendars. Neither issue applies with Temporal objects. Are there other problems that do apply even if the input is a Temporal object?

Related: is the current plan that Intl.DateTimeFormat.formatToParts will accept Temporal objects as input?

sffc commented 3 years ago

2021-01-14: agreed to remove month and weekday from this proposal.

littledan commented 3 years ago

This change to remove month and weekday isn't reflected in the README or spec text, yet it's still on the agenda for Stage 2.

If Temporal resolves these problems before Intl.DisplayNames v2 goes to Stage 3, could we add these things back into Intl.DisplayNames v2?

FrankYFTang commented 3 years ago

I am still working on changing the README to keep only "calendar" and "unit". The idea is Temporal itself will resolve the problem and no longer need them in DisplayNames.