Inconsistent DateTime format when using toLocaleString
See original GitHub issueI don’t know if this is related to something on my MacBook, but for some reason, my tests started failing with this:
const timestamp = "2022-05-11T23:23:00-07:00"; // Example timestamp string
DateTime.fromISO(timestamp, { zone: 'America/Los_Angeles' }).toLocaleString(DateTime.DATETIME_FULL);
On any other machine, this is the sample formatted output, but should be correct according to the documentation:
May 12, 2022, 7:00 AM PDT
On my Macbook, I would get this instead:
May 12, 2022 at 7:00 AM PDT
- OS: MacOS 13.0.1
- node.js version: 19.1.0
- Luxon version: 3.1.0
- Timezone: America/Los_Angeles
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Inconsistent behavior of toLocaleString() in different browser
Now at client side, I want this Date Time to be converted to Locale Date Time Format, like whatever is could be IST,...
Read more >Invalid Date generated by toLocaleString('en-gb', ...) #42391
As such, Node 13's behavior is correct. You're asking for a UK formatted date & getting one. When doing the reverse: The new...
Read more >Demystifying DateTime Manipulation in JavaScript - Toptal
Get the time stamp or the ISO formatted date from a REST API. Create a Date object. Use the toLocaleString() or toLocaleDateString() and...
Read more >Warning: Date.prototype.toLocaleFormat is deprecated
The JavaScript warning "Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead" occurs when the non-standard Date.prototype ...
Read more >ADR012: Use Luxon.toLocaleString and date/time presets
At the moment, plugins are defining dates and times using custom formats and the toFormat method, which leads to inconsistent and unfamiliar formats....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree that users of Luxon shouldn’t be testing against the output of
toLocaleString
; they should merely test that the inputs to Luxon are what they think they should be.However, Luxon itself needs to test, at the very least, that the inputs it sends to Intl are right. It doesn’t currently have a good way to do that, so we test the output of
toLocaleString
too. A refactor that gave us an Intl mock that we could assert against would fix this problem in Luxon’s own tests.Hey everyone. Tried out my test on Node19 and here’s what I got (works well on node 16, 17, 18):
In Node 19 space character code is
8239
and in “older” Node, including current LTS it’s32
Any ideas on a workaround?
Same space issue with both
DateTime.fromISO(date).toLocaleString(XXX)
andDateTime.fromISO(date).toFormat(XXXX, { locale })