by skeletal88 · 5y ago · 0 comments
It would be ideal to be able to use localized short and long month names, but be able to format the date and time as required.
Or there should be some other standard library/tool to format dates and times, because the JS ecosystem is a mess. Python is great in that way, that it includes everything needed, and you don't have to reinvent the wheel constantly, or try to find which random library does reinventing the best.
So they want "do the right thing" for 103 out of 104 locales, but "do what I told you" for "MY" locale.
This is a bit of a conundrum because we don't want to treat any locale as "special". To translate it to code you'd write something like:
if (currentLocale == "THE_ONE_UX_CREATED_MOCKS_FOR") {
let value = formatToUXProvidedPattern(data);
} else {
let value = data.toLocaleString(currentLocale);
}
I don't have a great answer how to approach it since there are severe drawbacks and risks to all known potential approaches to "squeeze just one particular format that UX provided into i18n database", but I just wanted to say that we're aware that Intl API has the clash with the UX-driven-development.The date means different things between the various English locales. In most of them, it means 1st February. In the USA, January 2nd.
Unfortunately, the very unusual US format is the default locale in many systems.
const a = new Date("2021/01/02"); // Sat Jan 02 2021 00:00:00 GMT-0800 (Pacific Standard Time)
const b = new Date("2021-01-02"); // Fri Jan 01 2021 16:00:00 GMT-0800 (Pacific Standard Time)
Date library authors have been bit hard because date parsing is hard, and they thought it would be easier to let the Date constructor do the job... only to find out via bug reports about the nasty obscurities of the date parsing rabbit hole.Proper date input usually requires a widget.