wrong calculation of .ceil() and .floor()
thinkrapido opened this issue · comments
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
Thanks, that does look like a bug.
To be sure, you'd expect the following output, is that right ?
epoch 2022-10-03T17:42:00 UTC
…On Mon, Oct 3, 2022, 11:42 Romeo Disca ***@***.***> wrote:
let epoch = Epoch::now().unwrap();//::from_unix_milliseconds(600f64);
println!("epoch {}", epoch);
println!("epoch {}", epoch .ceil(3.minutes()));
creates
epoch 2022-10-03T17:39:44.710711956 UTC
epoch 2022-10-03T17:41:23 UTC
—
Reply to this email directly, view it on GitHub
<#145>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABEZV2AOMGPGVEW2RXSMHETWBMLITANCNFSM6AAAAAAQ3Z6A4M>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
yes, it should be the appropriate fraction with seconds to zero
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.
@thinkrapido The bug is fixed in 3.5.0 in the way you wanted it to be fixed.