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
61
62
63
64
65
use crate::ffi::time_v1 as ffi;
pub use ffi::TimeFormat;
#[doc(hidden)]
pub use ffi::API as FFI_API;
#[derive(Copy, Clone)]
pub struct Time {}
#[derive(Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_speedy", derive(speedy::Writable, speedy::Readable))]
pub struct Instant(i64);
impl std::fmt::Debug for Instant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Time {}
.format_instant_for_display(*self, TimeFormat::ISODateTimeUTC)
.fmt(f)
}
}
impl Instant {
pub fn from_nanos_since_epoch(ns_since_epoch: i64) -> Self {
Self(ns_since_epoch)
}
pub fn as_nanos_since_epoch(self) -> i64 {
self.0
}
}
impl Time {
pub fn now(self) -> Instant {
Instant(ffi::time_utc())
}
pub fn format_instant_for_display(self, i: Instant, format: TimeFormat) -> String {
ffi::format_time_for_display(i.0, format)
}
}