Repository navigation
Wrong Intl.DateTimeFormat output for zh-CN without year part #29596
Description
Activity
Node v12.10.0
'09 ├Day: 16┤'
Node v12.10.0 with full-icu
'09-16'
I have verified that both v12.10.0 and v10.14.2 I tested are with small-icu, according to https://nodejs.org/docs/latest-v10.x/api/intl.html
new Intl.DateTimeFormat('es', { month: 'long' }).format(new Date(9e8)) // 'M01'v10.x is ok for Intl.DateTimeFormat + zh-CN but 12.x is not.
- addedi18n-apiIssues and PRs related to Node.js internationalization support.Issues and PRs related to Node.js internationalization support.
on Sep 18, 2019 Can't reproduce. Both master and v12.10.0 with small-icu pritn
'09/16'for me.edit: and to be clear: yes, that's a slash, not a dash.
@bnoordhuis I guess your system locale is en-US or similar (mine is zh-CN). If I run node v12.10.0 with a overwritten locale(
LANG=en-US node), I get'09/16'too. This behavior surprises me because I thought Intl.DateTimeFormat did not depend on system locale.With
LANG=zh-CNI can reproduce. Seems to be caused by the upgrade to ICU 64.2 in #27361 which means v10.16.0 and newer are also affected.I don't know if it's actually a bug but @srl295 can probably shed some light on that.
This behavior surprises me because I thought Intl.DateTimeFormat did not depend on system locale.
It does when ICU doesn't know the timezone name you pass to
Intl.DateTimeFormat.Fixing the fallback locale to some known-good value has been discussed in the past but being able to override it is sometimes useful.
@bnoordhuis I checked v10.16.3 and it doesn't affected (https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-x64.tar.xz ).
Omitting the
timeZoneoption doesn't change those results for me:new Intl.DateTimeFormat('zh-CN', { month: "2-digit", day: "2-digit" }).format(new Date('2019-09-16 GMT+8'))Hm, right. I reverted the ICU upgrade in my local v10.x branch and it indeed makes no difference.
I suppose that means a change in V8 is responsible (or the interaction between ICU and V8) but the diff between V8 6.8 and 7.6 is so big that it's hopeless to isolate the change.
There are plans to bundle full-icu with Node.js (#19214) so this issue will probably become moot in the not too distant future.
Omitting the timeZone option doesn't change those results for me:
Yes, I should have said "timezone or locale." (I did refer to the locale in the next sentence but not the first one.)
Sounds good to me. For now my workaround is adding a
year: "numeric"option and picking month and date parts from the result. Feel free to close this issue.Okay, I'll go ahead and do that.
For everyone coming here through search engines: installing the full-icu package should fix this in a forward compatible manner.
Reacted by Steven R. Loomis
Test code:
nodejs v12.10.0 outputs a strange string
'09 ├Day: 16┤'.On nodejs v10.14.2, the result is
'09-16', which is correct.