File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -64,11 +64,19 @@ public actual class Instant internal constructor(internal val value: jtInstant)
64
64
Instant (jtInstant.ofEpochMilli(epochMilliseconds))
65
65
66
66
public actual fun parse (isoString : String ): Instant = try {
67
- Instant (jtOffsetDateTime.parse(isoString).toInstant())
67
+ Instant (jtOffsetDateTime.parse(fixOffsetRepresentation( isoString) ).toInstant())
68
68
} catch (e: DateTimeParseException ) {
69
69
throw DateTimeFormatException (e)
70
70
}
71
71
72
+ /* * A workaround for a quirk of the JDKs older than 11 where the string representations of Instant that have an
73
+ * offset of the form "+XX" are not recognized by [jtOffsetDateTime.parse], while "+XX:XX" work fine. */
74
+ private fun fixOffsetRepresentation (isoString : String ): String {
75
+ val time = isoString.split(" T" ).elementAtOrNull(1 ) ? : return isoString
76
+ val offset = time.split(" +" , " -" ).elementAtOrNull(1 ) ? : return isoString
77
+ return if (offset.contains(" :" )) isoString else " $isoString :00"
78
+ }
79
+
72
80
public actual fun fromEpochSeconds (epochSeconds : Long , nanosecondAdjustment : Long ): Instant = try {
73
81
Instant (jtInstant.ofEpochSecond(epochSeconds, nanosecondAdjustment))
74
82
} catch (e: Exception ) {
You can’t perform that action at this time.
0 commit comments