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

Instant.parse(..) inconsistent between jvm and ios targets #369

Closed
HaukeRa opened this issue Mar 18, 2024 · 2 comments · Fixed by #370
Closed

Instant.parse(..) inconsistent between jvm and ios targets #369

HaukeRa opened this issue Mar 18, 2024 · 2 comments · Fixed by #370
Assignees
Labels
formatters Related to parsing and formatting
Milestone

Comments

@HaukeRa
Copy link

HaukeRa commented Mar 18, 2024

From ISO_DATE_TIME_OFFSET format:

.., except that during parsing, specifying the minutes is optional.

This format differs from LocalTime.Formats.ISO in its time part in that specifying the seconds is not optional.

JVM allows to ommit seconds (i.e. parse "2024-03-19T17:50Z") while builds for ios do not (fails with kotlinx.datetime.DateTimeFormatException: Parse error at char 16: expected char ':', got 'Z)

Omitting minutes, while allowed as per documentation, always fails for both targets.

@dkhalanskyjb dkhalanskyjb added the formatters Related to parsing and formatting label Mar 18, 2024
@dkhalanskyjb
Copy link
Collaborator

Thanks! The issue is that, on the JVM and the JS, we delegate to the platform-specific implementation of OffsetDateTime.parse, which does allow skipping the seconds: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html#parse-java.lang.CharSequence- We do that to work around the older JVM versions not supporting parsing arbitrary offsets, only Z.

The solution seems to be to stop relying on the platform implementation and use our version of ISO_DATE_TIME_OFFSET throughout.

Also, "omitting minutes" refers to the minutes of the UTC offset, that is, you can just have +03 instead of +03:00.

@HaukeRa
Copy link
Author

HaukeRa commented Mar 18, 2024

regarding minutes: my bad, can't read 🤦

It would be nice if both targets would behave equally, especially since folks tend to test on jvm/android and just expect (or hope) that ios will just work the same way. But, if read correctly, the documentation is right. Generally it is not allowed to ommit the seconds part.

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

Successfully merging a pull request may close this issue.

2 participants