Might handle leap seconds better
This commit is contained in:
parent
d0ce857365
commit
ecf78a4264
|
@ -51,6 +51,7 @@
|
|||
packages = [
|
||||
pkg-config
|
||||
dbus
|
||||
libfaketime
|
||||
toolchain.cargo
|
||||
toolchain.rustc
|
||||
toolchain.rustfmt
|
||||
|
|
|
@ -106,9 +106,11 @@ pub async fn local_time_stream(config: LocalTimeConfig) {
|
|||
..Default::default()
|
||||
};
|
||||
}
|
||||
let utc_next = utc_now.trunc_subsecs(0) + chrono::Duration::seconds(1);
|
||||
let difference = utc_next - utc_now;
|
||||
// It would take more resources to get time again, and we want to err on the side of
|
||||
// "wait a few µs too long" rather than too short.
|
||||
// Use a mod here in case someone handles leap seconds this way
|
||||
let difference = 1_000_000_000 - (utc_now.timestamp_subsec_nanos() % 1_000_000_000);
|
||||
|
||||
sleep(difference.to_std().unwrap()).await;
|
||||
sleep(std::time::Duration::from_nanos(difference.into())).await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,11 @@ pub async fn system_time_stream(config: SystemTimeConfig) {
|
|||
..Default::default()
|
||||
});
|
||||
|
||||
let next = now.trunc_subsecs(0) + chrono::Duration::seconds(1);
|
||||
let difference = next - now;
|
||||
// It would take more resources to get time again, and we want to err on the side of
|
||||
// "wait a few µs too long" rather than too short.
|
||||
// Use a mod here in case someone handles leap seconds this way
|
||||
let difference = 1_000_000_000 - (now.timestamp_subsec_nanos() % 1_000_000_000);
|
||||
|
||||
sleep(difference.to_std().unwrap()).await;
|
||||
sleep(std::time::Duration::from_nanos(difference.into())).await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,11 @@ pub async fn utc_time_stream(config: UtcTimeConfig) {
|
|||
..Default::default()
|
||||
});
|
||||
|
||||
let next = now.trunc_subsecs(0) + chrono::Duration::seconds(1);
|
||||
let difference = next - now;
|
||||
// It would take more resources to get time again, and we want to err on the side of
|
||||
// "wait a few µs too long" rather than too short.
|
||||
// Use a mod here in case someone handles leap seconds this way
|
||||
let difference = 1_000_000_000 - (now.timestamp_subsec_nanos() % 1_000_000_000);
|
||||
|
||||
sleep(difference.to_std().unwrap()).await;
|
||||
sleep(std::time::Duration::from_nanos(difference.into())).await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue