question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent DateTime format when using toLocaleString

See original GitHub issue

I 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:open
  • Created 10 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
icambroncommented, Nov 29, 2022

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.

0reactions
inomncommented, Dec 21, 2022

Hey everyone. Tried out my test on Node19 and here’s what I got (works well on node 16, 17, 18):

Screenshot 2022-12-21 at 15 41 58 Screenshot 2022-12-21 at 15 42 38

In Node 19 space character code is 8239 and in “older” Node, including current LTS it’s 32

Any ideas on a workaround?

Same space issue with both DateTime.fromISO(date).toLocaleString(XXX) and DateTime.fromISO(date).toFormat(XXXX, { locale })

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found