-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
regression - toLocaleString
as UTC TZ is displayed as short date (1 digit) on Node 21 but (2 digits) on Node 18
#51090
Comments
I also have this regression when updating from 21.2.0 to 21.3.0 or 21.4.0 |
Repro case:
Results:
|
The changes related to updating ICU to This change also included in the upcoming |
It's not a regression. Date formats change in response to changes in cultural and linguistic preferences. |
It should at least be mentionned as a breaking change in the release note |
Data changes constantly. Look at https://www.unicode.org/cldr/charts/44/delta/index.html and pick any locale. Node 18 is CLDR 43.1, Node 21 is 44. |
See #42440 (comment) for more discussion |
I know that ICU changes very often, and people are wrongly expect the output should be consistence inside the major version. As per the delta charts https://www.unicode.org/cldr/charts/44/delta/sv.html Randomly pick one that has date format changes for reference |
There are always changes.
That's true, so I'm not sure where the format came from. I'll see. |
You're right. Moreover this API shouldn't be expected to produce consistent result, and it's clearly stated in a note in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString So no breaking change here. |
this may actually be a v8 bug, ICU 74.1 gives:
also $ node
Welcome to Node.js v21.4.0.
Type ".help" for more information.
> new Intl.DateTimeFormat(['sv']).resolvedOptions();
{
locale: 'sv',
calendar: 'gregory',
numberingSystem: 'latn',
timeZone: 'America/Chicago',
year: 'numeric',
month: 'numeric',
day: 'numeric'
} but $ node
Welcome to Node.js v18.19.0.
Type ".help" for more information.
> new Intl.DateTimeFormat(['sv']).resolvedOptions();
{
locale: 'sv',
calendar: 'gregory',
numberingSystem: 'latn',
timeZone: 'America/Chicago',
year: 'numeric',
month: '2-digit',
day: '2-digit'
} |
by the way a test case that works past Dec 9th is new Date('2023-12-08T00:00:00.000Z').toLocaleDateString('sv') |
Chromium latest doesn't seem to be on ICU 74 yet. |
Upstream ICU bug https://unicode-org.atlassian.net/browse/ICU-22575 to be fixed in 74.2 |
I stand by what i said about this being a very bad idea for code. Perhaps the bug will flush out more of these incorrect usages. However, this particular bug seems to be an ICU bug. See https://bugzilla.mozilla.org/show_bug.cgi?id=1864612 for the parallel in Firefox. |
Not anymore, this change is not included now. |
@ghiscoding thank you for raising this issue in time to keep the bugs update out of 20.11.0. (By the way, the bug affected more than just this single date format in Swedish. I don't have a comprehensive list.) Meanwhile, ICU 74.2 is coming real soon now. |
You're more than welcome, this is my first reported issue in NodeJS project and I'm glad it got a lot of attentions from you guys. Thank you so much for supporting this great project :) |
@ghiscoding I have to say that NodeJS is a great project with a great community. Welcome! |
update: conventional-changelog has fixed their code to no longer misuse |
@srl295 I was assuming that the quoted commit might closes this issue but then realized it's for Node 20.x, was this commit also pushed to 21.x? |
I think the fix has landed on all active release lines, and can be closed now. |
Version
21.4.0
Platform
Microsoft Windows NT 10.0.19045.0 x64
Subsystem
No response
What steps will reproduce the bug?
Running the following script with today's date (2023-12-07) is displayed differently on Node 21 than it is on Node 18, this seems like a regression and I caused some failing unit tests in my CI because it expected a date format of YYYY-MM-DD but that is no longer true in Node 21.
This simple script
is displaying the following
Node 21
notice the December 7th is displayed as
7
instead of the expected07
Node 18
How often does it reproduce? Is there a required condition?
every time I tried on Node 21.4.x
What is the expected behavior? Why is that the expected behavior?
It should provide an ISO formatted date
What do you see instead?
December 7th is displayed as
7
instead of07
, below is a print screen of the simple script that I ran on Node 18 and 21Additional information
This date format script is used by
conventional-changelog
library here and the unit tests I have inLerna-Lite
failed only on Node 21 in this GitHub Action CI workflow because it expected a format ofYYYY-MM-DD
but it instead provided an unexpected format ofYYYY-MM-D
.The reason my unit tests failed is because, the tests are using a serializer replace any date to a static 'YYYY-MM-DD' text that the tests can compare test snapshot, but it started failing on Node 21 because the regex no longer found the expected date format. For now I changed the regex from
formattedDate.replace(/\(\d{4}-\d{2}-\d{2}\)/g, '(YYYY-MM-DD)')
toformattedDate.replace(/\(\d{4}-\d{1,2}-\d{1,2}\)/g, '(YYYY-MM-DD)')
and my tests are now passing again but it's still seem to be regression in Node 21Note that I'm on Windows but my CI is running on Ubuntu, so it's not an OS specific issue
As for the use of
sv-SE
locale, it looks like it's because Sweden has a fixed format that is unlikely to change and is the nearest to the ISO format as explained in this Stack Overflow answerThe text was updated successfully, but these errors were encountered: