use core::fmt;
use time::{macros::date, PrimitiveDateTime};
pub const EPOCH: PrimitiveDateTime = date!(1980 - 01 - 01).midnight();
pub trait Clock: fmt::Debug {
fn now(&self) -> PrimitiveDateTime;
}
#[derive(Debug, Default)]
#[allow(missing_copy_implementations)]
pub struct DefaultClock;
impl Clock for DefaultClock {
fn now(&self) -> PrimitiveDateTime {
#[cfg(feature = "std")]
{
use time::OffsetDateTime;
let now_odt = OffsetDateTime::now_local().unwrap_or(OffsetDateTime::now_utc());
PrimitiveDateTime::new(now_odt.date(), now_odt.time())
}
#[cfg(not(feature = "std"))]
EPOCH
}
}
impl Clock for &DefaultClock {
fn now(&self) -> PrimitiveDateTime {
(*self).now()
}
}