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

Calendar TimeRange has an off-by-one error in nanosecond calculation #5646

Closed
chipkent opened this issue Jun 21, 2024 · 0 comments · Fixed by #5648
Closed

Calendar TimeRange has an off-by-one error in nanosecond calculation #5646

chipkent opened this issue Jun 21, 2024 · 0 comments · Fixed by #5648
Assignees
Labels
bug Something isn't working triage

Comments

@chipkent
Copy link
Member

Looking at TimeRange::nanos:

    /**
     * Length of the range in nanoseconds.
     *
     * @return length of the range in nanoseconds
     */
    public long nanos() {
        return start.until(end, ChronoUnit.NANOS) - (inclusiveEnd ? 0 : 1);
    }

this seems incorrect.

For example, I would expect that

[ofEpochMilli(0), ofEpochMilli(1)) = 1,000,000 nanos
[ofEpochMilli(0), ofEpochMilli(1)] = 1,000,001 nanos

This makes me think a lot of the testing and calculations are off by 1.

but it seems like the code as written is providing

[ofEpochMilli(0), ofEpochMilli(1)) = 999,999 nanos
[ofEpochMilli(0), ofEpochMilli(1)] = 1,000,000 nanos

Originially identified in #5378 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant