Skip to content
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

Fix adding small Duration to large Instant on JS and Native #264

Merged
merged 1 commit into from Mar 30, 2023

Conversation

lukellmann
Copy link
Contributor

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.

fixes #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 Kotlin#263
@ilya-g ilya-g self-assigned this Mar 28, 2023
@ilya-g ilya-g merged commit 5a73782 into Kotlin:master Mar 30, 2023
@ilya-g
Copy link
Member

ilya-g commented Mar 30, 2023

Thanks for the fix!

@lukellmann lukellmann deleted the addition-bug branch March 30, 2023 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in Instant.plus(Duration) on JS for large Instants and small Durations
2 participants