-
Notifications
You must be signed in to change notification settings - Fork 101
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
Bug in Instant.plus(Duration)
on JS for large Instant
s and small Duration
s
#263
Comments
Can confirm that it also happens on native, will open a PR to fix this. |
Yes, makes sense to check for |
When adding a positive Duration < 1 second to an Instant far in the future for which the addition implementation overflows and throws an exception, the catch blocks would only check if the seconds component of the Duration is > 0. However since the Duration is < 1 second, the seconds component is not > 0 and Instant.MIN is returned instead of Instant.MAX. This was fixed by replacing the check against the seconds component of the Duration with a check against the whole Duration like it was already done in the JVM implementation. See Kotlin#263
When adding a positive Duration < 1 second to an Instant far in the future for which the addition implementation overflows and throws an exception, the catch blocks would only check if the seconds component of the Duration is > 0. However since the Duration is < 1 second, the seconds component is not > 0 and Instant.MIN is returned instead of Instant.MAX. This was fixed by replacing the check against the seconds component of the Duration with a check against the whole Duration like it was already done in the JVM implementation. See #263
When can we expect the next release containing the fix? |
I believe my issue might be related to this ticket, but wanted to check before opening a new one. The value was produced on "+5881633-11-04T10:50:52.288260993Z".toInstant() On native though converting that same |
@05nelsonm it's not related, Native and JS support a much smaller range of years than JVM, namely years |
Thanks. Will open a separate ticket then. Edit: created #269 |
Running this code on JS produces an unexpected result
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
seconds
is0
, resulting inInstant.MIN
being returnedThe line should probably be something like this instead:
The text was updated successfully, but these errors were encountered: