Date.toLocaleString()/Date.toLocaleFormat() don't respect selected locale on OS X
Categories
(Core :: JavaScript: Internationalization API, defect, P3)
Tracking
()
People
(Reporter: jwkbugzilla, Unassigned)
References
(Blocks 1 open bug)
Details
Reporter | ||
Comment 1•17 years ago
|
||
Comment 2•16 years ago
|
||
Updated•16 years ago
|
Comment 5•15 years ago
|
||
Reporter | ||
Comment 6•15 years ago
|
||
Comment 7•14 years ago
|
||
Updated•14 years ago
|
Assignee | ||
Updated•11 years ago
|
Comment 8•10 years ago
|
||
Comment 9•10 years ago
|
||
Comment 10•8 years ago
|
||
Comment 11•8 years ago
|
||
Comment 12•8 years ago
|
||
Comment 13•8 years ago
|
||
Comment 14•8 years ago
|
||
Comment 15•4 years ago
|
||
I develop the Tab Stash extension for Firefox, and I have received a bug report from a user which I think is actually this bug. The user has customized their date/time formats, and Firefox is not respecting these customizations when Tab Stash's JS code is calling Date.toLocaleString().
I was able to reproduce the issue on macOS 11.4 with Firefox 90.0—I changed my date/time settings so that dates are formatted as "YYYY-MM-DD", and yet new Date().toLocaleString()
still returns "M/D/YYYY"-formatted dates.
Would appreciate if this could be addressed, because it does have user-visible impacts. Thanks!
Updated•4 years ago
|
Updated•3 years ago
|
Comment 16•2 years ago
|
||
It looks like this issue is still occurring, but is not hardcoded to the american system. We appear to default to the locale (i.e. "de-DE") which has a hard coded time format without respecting the user system settings. On my machine (a German MacBook Pro), I get the following outcome:
new Date().toLocaleString()
"15/11/2023, 20:40:35"
This looks correct for the German convention, and aligns with my OS settings.
Updating my settings to display "YYYY-MM-DD" instead, I would expect to see:
new Date().toLocaleString()
"2023-11-15, 20:40:35"
However instead I see:
new Date().toLocaleString()
"15/11/2023, 20:40:35"
This would align with the behavior users have reported. I'm not sure if this is the intended behavior: https://tc39.es/ecma262/#sec-date.prototype.tolocalestring -- Based on the spec, I would expect the host to respect the system settings.
Comment 17•2 years ago
|
||
"15/11/2023, 20:40:35"
looks more like the expected result for locales like en-GB
instead of de-DE
, because the date separator is /
, whereas for German .
should be used.
I think intl.regional_prefs.use_os_locales
needs to be set to always use the OS preferences and ignore any locales from the (localised) Firefox installation: https://firefox-source-docs.mozilla.org/intl/locale.html#regional-preferences
Comment 18•2 years ago
|
||
Thanks for the follow up -- In this case, perhaps this is working as expected?
Updated•2 years ago
|
Comment 19•5 months ago
|
||
Possibly related. Running the following new Date(1743623960000).toLocaleString(['en-ES'])
.
outputs "4/2/2025, 7:59:20 PM" in Firefox and "2/4/2025, 7:59:20 PM" in Firefox Developer.
Same goes for date input. I get Month first in Firefox and Date first in Firefox Developer.
The system locale is set to en-ES and the installer used for both was en-GB.
Tested on Linux and Mac OS.
Comment 20•5 months ago
|
||
(In reply to Brahma Dev from comment #19)
Possibly related. Running the following
new Date(1743623960000).toLocaleString(['en-ES'])
.
outputs "4/2/2025, 7:59:20 PM" in Firefox and "2/4/2025, 7:59:20 PM" in Firefox Developer.
That behaviour is unrelated. Firefox Developer includes bug 1954425, which updates to ICU 77 and CLDR 47. As part of that update, en-ES
is now a new supported locale for date-time formatting. en-ES
follows en-150
(150 is the region code for Europe), which puts day of the month first. Firefox release doesn't yet contain the ICU update and therefore en-ES
falls back to en
(which is actually en-US
), so the month comes first. You can use new Intl.DateTimeFormat("en-ES").resolvedOptions().locale
to return the actually resolved locale. It'll return en-ES
in Firefox Developer, but en
in Firefox 137.
Comment 21•4 months ago
•
|
||
In an attempt to possibly clear things up:
- This bug -- as described in comment 0 -- is long fixed per comments 9-10 and 13: the formatting is not fixed to the "C" locale, the implementation does not use strftime(), and
Date.toLocaleFormat()
is removed. - The current behavior seems to agree with the specifications, though I'm not 100% sure I'm reading the specs correctly.
- OS System Settings (Language & Region) are not always honored, and it doesn't seem specific to macOS:
- Firefox/Gecko ignore the system settings if the system language doesn't match the Firefox's language (the one you pick when downloading, I believe) UNLESS
intl.regional_prefs.use_os_locales
(aka "Use your operating system settings for “...” to format dates, times, numbers, and measurements.") is set totrue
. (docs / code?), which makes sense for chrome (for the reasons given in the docs), but not so much for content. - Any customizations of the regional date and number formats are not supported. This seems to be a spec issue: Region Override Support #370, Allow for implementations to retrieve settings from host environment #109. See also bug 1575877
- The locale may be spoofed to combat fingerprinting; by default tracking protection does this to some sites, but it's possible to configure advanced protections, up to the nuclear option of
privacy.spoof_english = 2
. code can be traced from here
- Firefox/Gecko ignore the system settings if the system language doesn't match the Firefox's language (the one you pick when downloading, I believe) UNLESS
Up-to-date spec links:
- ECMA-262 delegates to ECMA-402 (Intl), when available: https://tc39.es/ecma262/#sec-date.prototype.tolocalestring
- ECMA-402: https://tc39.es/ecma402/#sup-date.prototype.tolocalestring
Description
•