cqlite_core/platform/
time.rs1use std::time::{Duration, SystemTime, UNIX_EPOCH};
4
5#[derive(Debug)]
7pub struct TimeProvider;
8
9impl Default for TimeProvider {
10 fn default() -> Self {
11 Self::new()
12 }
13}
14
15impl TimeProvider {
16 pub fn new() -> Self {
18 Self
19 }
20
21 pub fn now_micros(&self) -> u64 {
23 SystemTime::now()
24 .duration_since(UNIX_EPOCH)
25 .unwrap_or_else(|_| Duration::from_secs(0))
26 .as_micros() as u64
27 }
28
29 pub fn now_millis(&self) -> u64 {
31 SystemTime::now()
32 .duration_since(UNIX_EPOCH)
33 .unwrap_or_else(|_| Duration::from_secs(0))
34 .as_millis() as u64
35 }
36
37 pub fn now_secs(&self) -> u64 {
39 SystemTime::now()
40 .duration_since(UNIX_EPOCH)
41 .unwrap_or_else(|_| Duration::from_secs(0))
42 .as_secs()
43 }
44
45 pub fn now(&self) -> SystemTime {
47 SystemTime::now()
48 }
49
50 pub fn duration_from_millis(&self, millis: u64) -> Duration {
52 Duration::from_millis(millis)
53 }
54
55 pub fn duration_from_secs(&self, secs: u64) -> Duration {
57 Duration::from_secs(secs)
58 }
59}