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.

DateTime.fromFormat is not able to correctly parse the result of DateTime.toFormat()

See original GitHub issue

The following code results in an invalid DateTime:

const x = new Date();
DateTime.fromFormat(DateTime.fromJSDate(x).toFormat('D T'), 'D T')

error on the resulting DateTime object:

invalid: {…}
​​explanation: "you specified 20 (of type number) as a month, which is invalid"
​reason: "unit out of range"

I’m using firefox 84.0.2 on windows 10, lang in browser set to en-GB, windows region format set to Polish, windows display language set to en-GB, windows apps and websites land set to en-US.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dan-overtoncommented, Feb 21, 2021

I think if I was expecting US formatted dates from a backend, I’d expect to have to specify en-US explicitly in fromFormat. That is, I’d find having to do that that less unintuitive than this bug.

If that’s the expected behaviour though, I guess this one can be closed?

0reactions
spookycommented, Feb 19, 2021

I confirm that passing the locale explicitly in the options resolves this issue. The reason I reported it though is that when running on defaults for both fromFormat and toFormat, I’d expect this to use the same locale whereas it seems that’s not the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to format a Date with Luxon? - Stack Overflow
const date = DateTime.fromISO("2010-10-22T21:38:00") const humanReadable = date.toLocaleString(DateTime.
Read more >
How to use the luxon.DateTime.fromFormat function in ... - Snyk
To help you get started, we've selected a few luxon.DateTime.fromFormat examples, based on popular ways it is used in public projects.
Read more >
datetime — Basic date and time types — Python 3.11.1 ...
These tzinfo objects capture information about the offset from UTC time, the time zone name, and whether daylight saving time is in effect....
Read more >
Formatting and parsing dateTimes as strings - IBM
The following diagram shows how a pattern is used to format a dateTime source to produce a character string output.
Read more >
How to Carbon::Parse in dd/mm/yyyy format? - Laracasts
You do not need the accessors and mutators. The date will properly be stored and converted on output so long as you add...
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