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

DateTimeFormatter.ofPattern not working as expected with "zone-offset" #686

Open
gillstrom opened this issue Jun 2, 2023 · 4 comments
Open
Labels

Comments

@gillstrom
Copy link

Hi!
I'm not sure if this is a bug or if I misunderstand something here.

If I create a pattern with "zone-offset" using X and try to parse a string with +02:00, +02:30, etc. it throws a JsJodaException. Removing just the :XY part of the string I'm trying to parse make it work again.

Is this intended?


Example using @js-joda/core@5.5.3:

import {DateTimeFormatter, ZonedDateTime} from "@js-joda/core";

const SOME_PATTERN = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS][X]");

const working = ZonedDateTime.parse("2023-06-01T11:20:47.106+02", SOME_PATTERN);
// => ZonedDateTime {_dateTime: LocalDateTime {_date: LocalDate {_year: 2023, _month: 6, _day: 1}, …}, …}

const throwing = ZonedDateTime.parse("2023-06-01T11:20:47.106+02:00", SOME_PATTERN);
// => JsJodaException: Text '2023-06-01T11:20:47.106+02:00' could not be parsed, unparsed text found at index 26: 2023-06-01T11:20:47.106+02:00, at index: 26
@github-actions
Copy link

github-actions bot commented Sep 1, 2023

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Sep 1, 2023
@gillstrom
Copy link
Author

Should still be a problem.

@pithu pithu added bug and removed Stale labels Sep 1, 2023
@pithu
Copy link
Member

pithu commented Sep 1, 2023

Sounds like a bug from the upstream project to me

@pithu
Copy link
Member

pithu commented Sep 1, 2023

However, with pattern with three X eg DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS][XXX]") you can parse an offset with minutes.

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

No branches or pull requests

2 participants