Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library fails to parse time using fromFormat #714

Closed
RuLeZzz1987 opened this issue May 26, 2020 · 3 comments
Closed

Library fails to parse time using fromFormat #714

RuLeZzz1987 opened this issue May 26, 2020 · 3 comments

Comments

@RuLeZzz1987
Copy link

Settings.defaultLocale = 'es-ES';

DateTime.fromFormat('11:22 am', 'hh:mm a');

returns "the input "11:22 am" can't be parsed as format hh:mm a"
in case of es-ES locale /^(\d{2})(:)(\d{2})(\ )(a\.? m.|p\.? m.)$/i was used and for en-US - /^(\d{2})(:)(\d{2})(\ )(AM|PM)$/i

expected result: DateTime.fromFormat('11:22 am', 'hh:mm a') to be parsed without exceptions

@icambron
Copy link
Member

Yes, it looks like the local format for the meridiem is "a. m." or "p. m.":

> DateTime.local().setLocale("es-ES").toFormat("a") //=> 'p. m.'

So that's what Luxon is trying to parse. Luxon makes the dots optional for all tokens but it doesn't make spaces optional, hence the regex. So this is expected behavior.

We could offer a locale-insensitive meridiem token -- that would be a reasonable feature request.

@RuLeZzz1987
Copy link
Author

https://codesandbox.io/s/luxon-playground-lnruf?file=/src/index.js

Doesn't work for me with or without dots and spaces

@icambron
Copy link
Member

hmm, ok, i'll take a closer look

GillesDebunne added a commit to GillesDebunne/luxon that referenced this issue Aug 18, 2020
GillesDebunne added a commit to GillesDebunne/luxon that referenced this issue Aug 19, 2020
GillesDebunne added a commit to GillesDebunne/luxon that referenced this issue Aug 20, 2020
GillesDebunne added a commit to GillesDebunne/luxon that referenced this issue Aug 20, 2020
icambron added a commit that referenced this issue Sep 28, 2020
* remove console.log call and bump to 1.24.1

* update package-lock.json

* fix Interval.hasSame behaviour for empty intervals (#712)

Fixes #709

* Mark the package as side-effects-free (#713)

Addresses #710

* Add DATE_MED_WITH_WEEKDAY preset (#716)

* All tests assume America/NewYork timezone (#718)

* Add missing values in conversion matrices (#720)

* Remove normalization in ShiftTo (#721)

* RelativeTime test fails on last day of the month (#719)

* Update wording around date equality test (#725)

* Update wording around date equality test

As discussed in #108

* Fix for negative values in plus/minus. Fixes #645 and #669 (#722)

Requires the `fullConversionMatrices` and `noNormalizationInShiftTo` branches
to be merged first.

* Fixed typos in docs where 'month' was used in place of 'weekday' (#732)

* feat: add support for large durations in seconds (#737)

* Bump lodash from 4.17.14 to 4.17.19 (#739)

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.14 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.14...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Interval creation supports Settings.throwOnInvalid. Fixes #728 (#761)

* formatOffset handles signed offsets. Fixes #665 (#756)

* Update package-lock.json after npm install (#751)

Co-authored-by: Gilles Debunne <gilles.debunne@gmail.com>

* Add tests around DateTime.toISO() (#752)

* Round minutes in timezone offset display. Fixes #724 (#755)

* Support arbitrary precision in ISO milliseconds. Fixes #757 (#758)

* Support arbitrary precision in ISO milliseconds. Fixes #757

* Limit regex to 30 digits to prevent DOS

* fromFormat handles non breakable spaces. Fixes #714 (#762)

* Update Why page, remove outdated Relative references. Fixes #679. (#765)

* bump to 1.25.0

* Introduce DateTime.now() (#766)

* Bump codecov from 3.6.5 to 3.7.1 (#744)

Bumps [codecov](https://github.com/codecov/codecov-node) from 3.6.5 to 3.7.1.
- [Release notes](https://github.com/codecov/codecov-node/releases)
- [Commits](codecov/codecov-node@v3.6.5...v3.7.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update endOf() documentation with the same units as startOf() (#779)

* UnitFormat was folded into Unified NumberFormat (#785)

As per tc39/ecma402#32 (comment)

Co-authored-by: Isaac Cambron <isaac@isaaccambron.com>
Co-authored-by: downace <downace@users.noreply.github.com>
Co-authored-by: Ryota Kameoka <kameoka.ryota@gmail.com>
Co-authored-by: saltire <saltire@users.noreply.github.com>
Co-authored-by: Jon Knowles <jknowles@digitalprimates.net>
Co-authored-by: Jörg Bayreuther <jb@visualjerk.de>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Gilles Debunne <63719587+gdebunne@users.noreply.github.com>
Co-authored-by: Anthon Holmqvist <anthonkendel@users.noreply.github.com>
Co-authored-by: Bart Enkelaar <benkelaar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants