nyx-space / hifitime

A high fidelity time management library in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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
commented

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

commented

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.

commented

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