Might handle leap seconds better
This commit is contained in:
parent
d0ce857365
commit
ecf78a4264
|
@ -51,6 +51,7 @@
|
||||||
packages = [
|
packages = [
|
||||||
pkg-config
|
pkg-config
|
||||||
dbus
|
dbus
|
||||||
|
libfaketime
|
||||||
toolchain.cargo
|
toolchain.cargo
|
||||||
toolchain.rustc
|
toolchain.rustc
|
||||||
toolchain.rustfmt
|
toolchain.rustfmt
|
||||||
|
|
|
@ -106,9 +106,11 @@ pub async fn local_time_stream(config: LocalTimeConfig) {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let utc_next = utc_now.trunc_subsecs(0) + chrono::Duration::seconds(1);
|
// It would take more resources to get time again, and we want to err on the side of
|
||||||
let difference = utc_next - utc_now;
|
// "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()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let next = now.trunc_subsecs(0) + chrono::Duration::seconds(1);
|
// It would take more resources to get time again, and we want to err on the side of
|
||||||
let difference = next - now;
|
// "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()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let next = now.trunc_subsecs(0) + chrono::Duration::seconds(1);
|
// It would take more resources to get time again, and we want to err on the side of
|
||||||
let difference = next - now;
|
// "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