Closed
Description
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 aDateTimeException
- here is the actual bug: because the added amount is smaller than one second,
seconds
is0
, resulting inInstant.MIN
being returned
The line should probably be something like this instead:
if (duration.isPositive()) MAX else MIN