-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix timezone extraction to work in all locales #21596
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
Conversation
en-US locale when extracting timezone infoen-US locale when extracting timezone info
|
Could you do something like: https://stackoverflow.com/a/78194184 ? I don't know if timeZoneName is guaranteed to exist, based on the Mozilla docs on Intl.DateTimeFormat so you might want some error checks around that. |
The My reading of the MDN page is that |
en-US locale when extracting timezone info
I tested this code going back to node v14.1.0 and also in the d8 shell and it seems to work fine. |
|
One more thing and I promise I'll leave you alone. :) You might want to have a test with a time in a timezone with a 15 or 30 minute offset. For example:
returns I am SO sorry this blew up into so much work. Time zones and locales are HARD. |
Do you know how POSIX/glibc handles this case? Should we just silently truncate to 6 chars since this is such an outlier case? |
Answering my own question it looks like glibc prints |
|
Updated |
416cf52 to
ab2068f
Compare
|
This test is failing on mac on the Chromium CI bots: https://logs.chromium.org/logs/emscripten-releases/buildbucket/cr-buildbucket/8752412488426808241/+/u/Emscripten_testsuite__other_/stdout |
|
Oh way, I disabled it under macOS on github CI, but maybe I just need to disable it completely on macOS. @dschuff can you confirm if fails for you locally on your mac? Do you think is reasonable to simpley not support the locale testing on mac for this reason? |
|
Yes, this fails locally for me with Which is the same failure on the Chromium bots, and I guess is the same failure you saw on Circle, right (i.e. python just doesn't work when you ask it for a locale that's not on the system?) |
|
Do you know how locales work on macOS? Is this s limitation of the OS, or of the python executable that we ship? |
|
No idea how locales work really. The python executable I'm using locally is not the one we ship though. |
|
OK I think we will just have to disable that test on mac in all cases then. |
With certain language I've noticed that the timezone extraction
algorithm doesn't work. or example consider the following:
Test file:
```JavaScript
const date = new Date();
console.log(date.toLocaleTimeString(undefined, {hour12: false, timeZoneName: 'short'}))
```
Run test file with specific local such as `th-TH` or `ar-AE`
```bash
LC_ALL="th-TH" TZ="Asia/Bangkok" node test.js
# prints "15 นาฬิกา 53 นาที 54 วินาที GMT+7"
```
And so the current logic for extracting would fail and return "นาฬิกา" (second item when splitting by space)
In this PR, a new approach is proposed for extracting the timezone offset and tests are updated with new test-case
See #21596
…ten-core#22250) With certain language I've noticed that the timezone extraction algorithm doesn't work. or example consider the following: Test file: ```JavaScript const date = new Date(); console.log(date.toLocaleTimeString(undefined, {hour12: false, timeZoneName: 'short'})) ``` Run test file with specific local such as `th-TH` or `ar-AE` ```bash LC_ALL="th-TH" TZ="Asia/Bangkok" node test.js # prints "15 นาฬิกา 53 นาที 54 วินาที GMT+7" ``` And so the current logic for extracting would fail and return "นาฬิกา" (second item when splitting by space) In this PR, a new approach is proposed for extracting the timezone offset and tests are updated with new test-case See emscripten-core#21596
Followup to #21585