DateTime.fromFormat is not able to correctly parse the result of DateTime.toFormat()
See original GitHub issueThe 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:
- Created 3 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top 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 >
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 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?
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
andtoFormat
, I’d expect this to use the same locale whereas it seems that’s not the case.