diff --git a/src/time/mod.rs b/src/time/mod.rs index ff99832..db0e1b3 100644 --- a/src/time/mod.rs +++ b/src/time/mod.rs @@ -22,7 +22,8 @@ use crate::{ }; /// A measurement of the system clock, useful for talking to external entities -/// like the file system or other processes. +/// like the file system or other processes. May be converted losslessly to a +/// more useful `std::time::SystemTime` to provide more methods. #[derive(Debug, Clone, Copy)] #[allow(dead_code)] pub struct SystemTime(wall_clock::Datetime); @@ -33,6 +34,14 @@ impl SystemTime { } } +impl From for std::time::SystemTime { + fn from(st: SystemTime) -> Self { + std::time::SystemTime::UNIX_EPOCH + + std::time::Duration::from_secs(st.0.seconds) + + std::time::Duration::from_nanos(st.0.nanoseconds.into()) + } +} + /// An async iterator representing notifications at fixed interval. pub fn interval(duration: Duration) -> Interval { Interval { duration }