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.

Weird behaviour with DateTime toLocaleString and DateTime fromFormat

See original GitHub issue

Describe 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:closed
  • Created 10 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
diesieben07commented, Dec 6, 2022

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

0reactions
tonysampericommented, Dec 6, 2022

@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!

Read more comments on GitHub >

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

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