whiskers.git / crates / whiskersd / src / clock.rs
1//! The system clock.
2
3use std::time::{SystemTime, UNIX_EPOCH};
4
5use whiskers_ports::{Clock, Millis};
6
7#[derive(Clone, Copy, Debug, Default)]
8pub struct SystemClock;
9
10impl Clock for SystemClock {
11    fn now(&self) -> Millis {
12        Millis::new(SystemTime::now().duration_since(UNIX_EPOCH).map_or(0, |d| d.as_millis() as u64))
13    }
14}