-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NodeJS not applying date locales properly #8500
Comments
By default |
There is another option that doesn't require a custom build of node. You can install the |
Thank you! At least this is now up somewhere where others can find it. |
Funny that "JavaScript" or NodeJs can offer a built-in function (new Date()).toLocaleDateString('de-CH'); // 2019-11-8 // Wrong Installing |
I experienced this with my colleague while running integration tests on our app, we were using
NodeJS@12: I seek enlightenment. |
The official distribution of Node 13 includes 'full icu': the locale database. Without that data Node only supports 'en-US' and will throw for other languages, and silently fall back to 'en-US' for English with other countries. What makes that so insidious is that no other English countries use the US date format and most use the British format which can be ambiguous so you won't even realize it is wrong. If you have control over your Node invocation (ie. you are not using 3rd party FaaS) then you can add 'full icu' to earlier versions of node via a flag and a data file. |
I don't understand why localization is "tacked" on to node like this. Surely date formats for 100 or so countries can't be more than a kb or so of additional weight. |
1kb allows about 5 bytes per country in the world.... ICU is much, much, much larger and more complex than that. |
Not sure what you mean by "tacked". We discussed this way back in 2014 nodejs/node-v0.x-archive#6371 (comment) , this was a deliberate and theoretically well documented decision to avoid doubling the download size of node. |
What I mean is that the JavaScript experience is core + modules and now it's core + modules + thisOtherThing. It makes developing and operating node a pain since I now have to manage a dependency and environment variable instead of just installing a module. In fact, pains with this mean myself and others will drop ICU and install a 3rd party module. Whilst there may be 100+ countries there are not 100+ date formats - probably half a dozen or so. |
For anyone that stumbles across this issue, it seems all locales are now included as of node v13: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V13.md#2019-10-22-version-1300-current-bethgriggs |
@WickyNilliams yes, this is true. |
On Linux (CentOS) Node seems to ignore the system locale and produce US Date format MM/dd/yyyy: (new Date()).toLocaleDateString()
'11/30/2020' Anyone know where the locale can be set which Node uses?
|
@cawoodm you could pass the locale you require as a parameter to
|
this looks like CentOS is choosing an English format also. you can set $ env LC_ALL=de_CH.UTF8 node -p 'new Date().toLocaleString()'
2021-1-7 12:59:11 |
In all three of my environments I was able to reproduce this error:
My production server
My primary development machine
My secondary development machine
I can't get nodejs to properly format a datetime string in the machine locale. On all of these machines the locale is set to British English, and when recreated on each machine, I get the same output, so I'll just post it once.
The expected behaviour is as such with the en-GB locale set:
I get:
However, when tested in the chrome console, I get the following:
What's going on here? Am I doing something wrong, or is there a bug here?
The text was updated successfully, but these errors were encountered: