use crate::Duration;
use std::time::SystemTime;
#[deprecated(
since = "0.34.0",
note = "moved to the pna crate; use pna::prelude::SystemTimeDurationExt::try_duration_since_unix_epoch_signed or saturating_duration_since_unix_epoch_signed"
)]
pub trait SystemTimeExt {
fn duration_since_unix_epoch_signed(&self) -> Duration;
}
#[allow(deprecated)]
impl SystemTimeExt for SystemTime {
#[inline]
fn duration_since_unix_epoch_signed(&self) -> Duration {
time::OffsetDateTime::from(*self) - time::OffsetDateTime::UNIX_EPOCH
}
}
#[cfg(test)]
mod tests {
use super::*;
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[allow(deprecated)]
#[test]
fn unix_epoch_returns_zero() {
assert!(
SystemTime::UNIX_EPOCH
.duration_since_unix_epoch_signed()
.is_zero()
);
}
}