-
Notifications
You must be signed in to change notification settings - Fork 127
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
tai64: wrong results -- 10s is not right offset and doesn't account for past or future leap seconds in SystemTime conversion #675
Comments
comparison on my system (after installing ntp so linux has the correct offset): use tai64::Tai64N;
use std::time::SystemTime;
use libc::{clock_gettime, CLOCK_TAI, timespec};
fn now_tai() -> std::io::Result<timespec> {
let mut retval = timespec { tv_sec: 0, tv_nsec: 0 };
let r = unsafe { clock_gettime(CLOCK_TAI, &mut retval) };
if r != 0 {
Err(std::io::Error::last_os_error())
} else {
Ok(retval)
}
}
fn main() {
let t = dbg!(Tai64N::now());
let t = (t.0.0 as i64).wrapping_sub(1 << 62);
dbg!(t);
dbg!(SystemTime::now());
let tai = now_tai().unwrap();
dbg!(tai.tv_sec);
dbg!(tai.tv_nsec);
} output:
|
The implementation is indeed naive/broken. I thought we had an open tracking issue for this, but apparently not. I'm not sure the best way to handle this, especially given the existing published crates. |
how about downloading the official leap-second table and converting it to rust in a build.rs? you could have that enabled by an enabled-by-default feature. apparently an official source is https://www.ietf.org/timezones/data/leap-seconds.list |
I'd probably suggest against making network connections from a build script, especially in any security-related package (indeed there are renewed efforts underway to run build scripts under WASM). However, I think it would be okay to use AOT conversion of the table, leveraging the build script as a sort of "time bomb" which makes the crate fail to compile after the table expires. Or we could add some sort of automation to yank the crate releases containing expired tables. |
for wireguard compatibility, you could add a disabled-by-default feature |
ok, at least on linux you can usually get an up-to-date table from the tzdata package which is usually installed by default: |
apparently recent versions of windows store the leap second table in the registry: |
Perhaps it could try to query OS facilities to find the table, and if it can't, fall back on an internal table. |
The offset between UTC time and TAI time isn't currently 10s, it's 37s and may change to something other than 37s in the future.
The current code assumes the offset is always 10s.
The text was updated successfully, but these errors were encountered: