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

usage of ISO_ZONED_DATE_TIME as default formatter in encoder #2239

Open
an-tex opened this issue Mar 5, 2024 · 2 comments
Open

usage of ISO_ZONED_DATE_TIME as default formatter in encoder #2239

an-tex opened this issue Mar 5, 2024 · 2 comments

Comments

@an-tex
Copy link
Contributor

an-tex commented Mar 5, 2024

The default encoder for ZonedDateTime uses the ISO_ZONED_DATE_TIME formatter, which is only "ISO-like" as it

extends the ISO-8601 extended offset date-time format to add the time-zone. The section in square brackets is not part of the ISO-8601 standard

This results in parsing issues if this encoder is used outside of the JVM, e.g. when using circe to encode ZonedDateTime which is returned in a REST API. E.g. by default JavaScript is not able to decode it:

console.log(Date.parse('2024-03-05T10:04:49.49661+01:00')); // ISO_OFFSET_DATE_TIME, ISO-8601 Europe/Berlin
console.log(Date.parse('2024-03-05T09:01:07.763452Z')); // ISO_OFFSET_DATE_TIME, ISO-8601 UTC
console.log(Date.parse('2024-03-05T08:55:22.97961Z[UTC]')); // ISO_ZONED_DATE_TIME UTC

results in

> 1709629489496
> 1709629267763
> NaN

Given this, I'd argue circe should use ISO_OFFSET_DATE_TIME as the formatter for the default encoder to be ISO conformant and allow compatibility esp. when used outside of the JVM.

This shouldn't have an impact on the decoder as it can handle both formats

@hamnis
Copy link
Collaborator

hamnis commented Apr 15, 2024

This seems reasonable, are you willing to add a PR for this?

@an-tex
Copy link
Contributor Author

an-tex commented Apr 17, 2024

yep i'll try to squeeze it in the next weeks

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

2 participants