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

Date parser fails when device is in 12-Hour Time mode #796

Open
matejhacin opened this issue Jun 1, 2022 · 2 comments
Open

Date parser fails when device is in 12-Hour Time mode #796

matejhacin opened this issue Jun 1, 2022 · 2 comments

Comments

@matejhacin
Copy link

Hello, I am parsing dates in my app using this library and I've just noticed an issue when my device is in 12-Hour Time mode.

The API I am working with can return dates in two different formats:

Format A: 2021-12-06T00:00:00
Format B: 2020-06-10T06:00:00.785+02:00

Parsing Format B always works whether device is in 12-Hour or 24-Hour mode.

Parsing Format A however, will fail if the device is in 12-Hour mode. It does work in 24-Hour mode.

I am currently using a temporary workaround, by providing my own formatter and Region when using the toDate() extension. Like this:

"2020-06-10T06:00:00".toDate() // Fails in 12-Hour Time mode
"2020-06-10T06:00:00".toDate("yyyy-MM-dd'T'hh:mm:ss", region: Region.UTC) // Works both in 12-Hour and 24-Hour mode

@wonder2011
Copy link

wonder2011 commented Jun 29, 2022

@matejhacin Try parsing dateA with .toDate("yyyy-MM-dd'T'hh:mm:ss", region: Region.ISO) !

@marcbaldwin
Copy link

I faced this problem but was able to fix it by setting the Locale of the Region to "en_US_POSIX". You can read more about why this works here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants