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
// =============================================================================
// #######
// ### ### F: clock.rs
// ## ## ## ## P: AppCore-Runtime
// ## ##
// C: 2026/06/07 11:20:00 by dnettoRaw
// ## ## ## ## U: 2026/06/07 11:20:00 by dnettoRaw
// ########### S: 0.6.0
// =============================================================================
//! Mockable clock utilities for retrieving standard timestamps.
use std::time::{SystemTime, UNIX_EPOCH};
/// Mockable clock trait for fetching millisecond timestamps.
pub trait Clock: Send + Sync + std::fmt::Debug {
/// Returns the current epoch time in milliseconds.
fn now_ms(&self) -> u64;
}
/// Standard system clock implementation using `std::time::SystemTime`.
#[derive(Debug, Clone, Copy, Default)]
pub struct SystemClock;
impl SystemClock {
/// Create a new instance of the system clock.
pub fn new() -> Self {
Self
}
}
impl Clock for SystemClock {
fn now_ms(&self) -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_millis() as u64)
.unwrap_or(0)
}
}