use std::time::Duration;
pub trait TimeUnits {
fn ms(self) -> Duration;
fn secs(self) -> Duration;
fn minutes(self) -> Duration;
fn hours(self) -> Duration;
}
impl TimeUnits for u64 {
fn ms(self) -> Duration {
Duration::from_millis(self)
}
fn secs(self) -> Duration {
Duration::from_secs(self)
}
fn minutes(self) -> Duration {
Duration::from_secs(self * 60)
}
fn hours(self) -> Duration {
Duration::from_secs(self * 60 * 60)
}
}
impl TimeUnits for f32 {
fn ms(self) -> Duration {
Duration::from_secs_f32(self / 60.0)
}
fn secs(self) -> Duration {
Duration::from_secs_f32(self)
}
fn minutes(self) -> Duration {
Duration::from_secs_f32(self * 60.0)
}
fn hours(self) -> Duration {
Duration::from_secs_f32(self * 60.0 * 60.0)
}
}