Skip to content

Broken guarantee in Instant.until #488

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

Open
dkhalanskyjb opened this issue Feb 18, 2025 · 0 comments
Open

Broken guarantee in Instant.until #488

dkhalanskyjb opened this issue Feb 18, 2025 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@dkhalanskyjb
Copy link
Collaborator

Almost equivalent to #484, but more pronounced.

From the documentation:

Returns the whole number of the specified date or time units between this and other instants in the specified timeZone.

This is not true: "the whole number" implies "the number rounded towards zero to the nearest whole number", but that's not what we get:

import kotlinx.datetime.*

fun main() {
    val tz = TimeZone.of("Europe/Berlin")
    val i1 = LocalDateTime(2025, 3, 29, 2, 30).toInstant(tz)
    val i2 = LocalDateTime(2025, 3, 30, 3, 10).toInstant(tz)
    println(i2 - i1.plus(i1.until(i2, DateTimeUnit.DAY, tz), DateTimeUnit.DAY, tz)) // -20m
}

b - (a + floor(b - a)) should be non-negative for positive b and a, but here, it's not.

@dkhalanskyjb dkhalanskyjb added breaking change This could break existing code bug Something isn't working and removed breaking change This could break existing code labels Apr 9, 2025
@dkhalanskyjb dkhalanskyjb added this to the 0.9.0 milestone Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant