Skip to content

Fix Instant parsing on Native being too lenient #182

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/common/test/InstantTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class InstantTest {
assertEquals(seconds.toLong() * 1000 + nanos / 1000000, instant.toEpochMilliseconds())
}

// TODO: assertInvalidFormat { Instant.parse("1970-01-01T23:59:60Z")} // fails on Native
assertInvalidFormat { Instant.parse("1970-01-01T23:59:60Z")}
assertInvalidFormat { Instant.parse("1970-01-01T24:00:00Z")}
assertInvalidFormat { Instant.parse("x") }
assertInvalidFormat { Instant.parse("12020-12-31T23:59:59.000000000Z") }
// this string represents an Instant that is currently larger than Instant.MAX any of the implementations:
Expand Down
5 changes: 2 additions & 3 deletions core/native/src/Instant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ private val instantParser: Parser<Instant>

val nano = nanosVal ?: 0
val (days, hours, min, seconds) = if (hoursVal == 24 && minutesVal == 0 && secondsVal == 0 && nano == 0) {
listOf(1, 0, 0, 0)
throw DateTimeFormatException("24:00:00 is an unsupported time-of-day")
} else if (hoursVal == 23 && minutesVal == 59 && secondsVal == 60) {
// TODO: throw an error on leap seconds to match what the other platforms do
listOf(0, 23, 59, 59)
throw DateTimeFormatException("Leap seconds are not supported")
} else {
listOf(0, hoursVal, minutesVal, secondsVal)
}
Expand Down