use crate::{
platform::{utc_now, DateTime},
TimeSpan,
};
use core::ops::Sub;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct AtomicDateTime {
pub time: DateTime,
pub synced_with_atomic_clock: bool,
}
impl AtomicDateTime {
pub const fn new(time: DateTime, synced_with_atomic_clock: bool) -> Self {
Self {
time,
synced_with_atomic_clock,
}
}
#[inline]
pub fn now() -> Self {
AtomicDateTime {
time: utc_now(),
synced_with_atomic_clock: false,
}
}
}
impl Sub for AtomicDateTime {
type Output = TimeSpan;
fn sub(self, rhs: AtomicDateTime) -> TimeSpan {
(self.time - rhs.time).into()
}
}
impl Sub<DateTime> for AtomicDateTime {
type Output = TimeSpan;
fn sub(self, rhs: DateTime) -> TimeSpan {
(self.time - rhs).into()
}
}