Weird behaviour with DateTime toLocaleString and DateTime fromFormat
See original GitHub issueDescribe the bug We can generate a string with a certain locale, but we can’t parse it.
To Reproduce
luxon.DateTime.local().reconfigure({ locale: "es-ES"}).toLocaleString({
...luxon.DateTime.TIME_SIMPLE,
hourCycle: "h12"
});
// '7:42 p. m.'
luxon.DateTime.fromFormat("02:00 a. m.", "hh:mm a", {locale: "es-ES", numberingSystem: "latin"});
// Invalid date time with reason: the input \"02:00 a. m.\" can't be parsed as format [object Object]
Actual vs Expected behavior
I guess it would make sense it worked both ways
Desktop (please complete the following information):
- OS: Win 11
- Browser: Chrome 107.0.5304.122
- Luxon version: 3.1.1
- Your timezone: “Europe/Rome”
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5
Top Results From Across the Web
Strange behavior of toLocaleString() method
The return value of setMonth() is a number, not a Date . Just use the mutated dateValue instead: let value = "2018-11-26T10:00:00.000Z"; ...
Read more >DateTime.fromFormat does not handle zone correctly #1198
Describe the bug DateTime.fromFormat does not handle zone correctly. Only UTC zone is working as expected. To Reproduce Please share a ...
Read more >luxon 3.1.1 | Documentation
A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for ......
Read more >luxon | Yarn - Package Manager
Luxon is a library for working with dates and times in JavaScript. DateTime.now().setZone("America/New_York").minus({ weeks: 1 }).endOf("day").toISO(); ...
Read more >Weird behaviour with DateTime toLocaleString ... - PullAnswer
toLocaleString ({ ...luxon.DateTime.TIME_SIMPLE, hourCycle: "h12" }); // '7:42 p. m.' luxon.DateTime.fromFormat("02:00 a. m.", "hh:mm a", ...
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
You’re looking for the
latn
numbering system.latin
is not a valid option here. This input should probably be validated. You can find the list of valid numbering systems on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem@diesieben07
Thanks! No worries, though! It’s proven to work…I just have to deal with some legacy code which for no apparent reason defaults to parsing in us locale… Btw before opening this, I bypassed the issue transforming any weird representation of the meridiem to AM or PM… But I’ll see if I can do something cleaner!