Skip to content

Commit 3b97964

Browse files
authored
wstd::time::SystemTime can be converted to std::time::SystemTime (#120)
1 parent 21434fa commit 3b97964

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/time/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use crate::{
2222
};
2323

2424
/// A measurement of the system clock, useful for talking to external entities
25-
/// like the file system or other processes.
25+
/// like the file system or other processes. May be converted losslessly to a
26+
/// more useful `std::time::SystemTime` to provide more methods.
2627
#[derive(Debug, Clone, Copy)]
2728
#[allow(dead_code)]
2829
pub struct SystemTime(wall_clock::Datetime);
@@ -33,6 +34,14 @@ impl SystemTime {
3334
}
3435
}
3536

37+
impl From<SystemTime> for std::time::SystemTime {
38+
fn from(st: SystemTime) -> Self {
39+
std::time::SystemTime::UNIX_EPOCH
40+
+ std::time::Duration::from_secs(st.0.seconds)
41+
+ std::time::Duration::from_nanos(st.0.nanoseconds.into())
42+
}
43+
}
44+
3645
/// An async iterator representing notifications at fixed interval.
3746
pub fn interval(duration: Duration) -> Interval {
3847
Interval { duration }

0 commit comments

Comments
 (0)