appcore_core/clock.rs
1// =============================================================================
2// #######
3// ### ### F: clock.rs
4// ## ## ## ## P: AppCore-Runtime
5// ## ##
6// C: 2026/06/09 08:35:21 by dnettoRaw
7// ## ## ## ## U: 2026/06/09 08:35:21 by dnettoRaw
8// ########### S: 1.0.1-rc.8
9// =============================================================================
10
11//! Mockable clock utilities for retrieving standard timestamps.
12
13use std::time::{SystemTime, UNIX_EPOCH};
14
15/// Mockable clock trait for fetching millisecond timestamps.
16pub trait Clock: Send + Sync + std::fmt::Debug {
17 /// Returns the current epoch time in milliseconds.
18 fn now_ms(&self) -> u64;
19}
20
21/// Standard system clock implementation using `std::time::SystemTime`.
22#[derive(Debug, Clone, Copy, Default)]
23pub struct SystemClock;
24
25impl SystemClock {
26 /// Create a new instance of the system clock.
27 pub fn new() -> Self {
28 Self
29 }
30}
31
32impl Clock for SystemClock {
33 fn now_ms(&self) -> u64 {
34 SystemTime::now()
35 .duration_since(UNIX_EPOCH)
36 .map(|d| d.as_millis() as u64)
37 .unwrap_or(0)
38 }
39}