1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::platform::utc_now;
use crate::TimeSpan;
use chrono::{DateTime, Utc};
use std::ops::Sub;
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct AtomicDateTime {
pub time: DateTime<Utc>,
pub synced_with_atomic_clock: bool,
}
impl AtomicDateTime {
pub fn new(time: DateTime<Utc>, 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.signed_duration_since(rhs.time).into()
}
}
impl Sub<DateTime<Utc>> for AtomicDateTime {
type Output = TimeSpan;
fn sub(self, rhs: DateTime<Utc>) -> TimeSpan {
self.time.signed_duration_since(rhs).into()
}
}