Running this code on JS produces an unexpected result
val instant = Instant.fromEpochMilliseconds(Long.MAX_VALUE) + 999_999.nanoseconds
println(instant) // expected some positive (clamped) value, got -1000000-01-01T00:00:00Z
The reason for this seems to be this line of code.
Instant.fromEpochMilliseconds(Long.MAX_VALUE)
gives the max instant on JS (+1000000-12-31T23:59:59.999999999Z
)
plusFix
overflows and throws a DateTimeException
- here is the actual bug: because the added amount is smaller than one second,
seconds
is 0
, resulting in Instant.MIN
being returned
The line should probably be something like this instead:
if (duration.isPositive()) MAX else MIN