kotlinx-datetime
kotlinx-datetime copied to clipboard
Instant.parse(..) inconsistent between jvm and ios targets
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.
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
.
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.