mod historical;
mod precision_clock;
#[cfg(any(test, feature = "testing"))]
mod test_clock;
use std::time::Instant;
pub use historical::{HistoricalClock, Interval};
pub use precision_clock::PrecisionClock;
pub use time::{Duration, OffsetDateTime};
#[cfg(any(test, feature = "testing"))]
pub use test_clock::TestClock;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct CycleTime {
instant: Instant,
unix_time: OffsetDateTime,
}
impl CycleTime {
pub fn new(instant: Instant, system_time: OffsetDateTime) -> Self {
Self {
instant,
unix_time: system_time,
}
}
pub const fn now(&self) -> Instant {
self.instant
}
pub const fn unix_timestamp(&self) -> OffsetDateTime {
self.unix_time
}
pub const fn unix_timestamp_nanos(&self) -> i128 {
self.unix_time.unix_timestamp_nanos()
}
}
pub trait Clock {
fn cycle_time(&mut self) -> CycleTime;
}