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

wrong calculation of .ceil() and .floor() #145

Closed
thinkrapido opened this issue Oct 3, 2022 · 4 comments · Fixed by #146
Closed

wrong calculation of .ceil() and .floor() #145

thinkrapido opened this issue Oct 3, 2022 · 4 comments · Fixed by #146
Assignees
Labels

Comments

@thinkrapido
Copy link

thinkrapido commented Oct 3, 2022

    let epoch = Epoch::from_unix_milliseconds(600f64);

    println!("epoch {}", epoch);
    println!("epoch {}", epoch .ceil(3.minutes()));
    println!("epoch {}", epoch .floor(3.minutes()));

    let epoch = Epoch::now().unwrap();//::from_unix_milliseconds(600f64);

    println!("epoch {}", epoch);
    println!("epoch {}", epoch .ceil(3.minutes()));
    println!("epoch {}", epoch .floor(3.minutes()));

creates

epoch 1970-01-01T00:00:00.599999904 UTC
epoch 1970-01-01T00:03:00 UTC
epoch 1970-01-01T00:00:00 UTC
epoch 2022-10-03T17:44:29.898032665 UTC
epoch 2022-10-03T17:47:23 UTC                         # error
epoch 2022-10-03T17:44:23 UTC                         # error
@ChristopherRabotin
Copy link
Member

ChristopherRabotin commented Oct 3, 2022 via email

@thinkrapido
Copy link
Author

yes, it should be the appropriate fraction with seconds to zero

@ChristopherRabotin
Copy link
Member

The source of the issue is that the floor function will floor the duration that is stored in the epoch. However, all epochs are stored in TAI so all of the floor and ceil is done in TAI. There's a non-constant offset between TAI and UTC, hence the rounding you're seeing.

I'm implementing a fix now that adds a ceil and floor function with in a given time system.

@ChristopherRabotin
Copy link
Member

@thinkrapido The bug is fixed in 3.5.0 in the way you wanted it to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants