chute_kun/lib/clock.rs
1//! Clock abstraction to obtain local wall-clock time in minutes since midnight.
2//!
3//! - `Clock` trait enables injection for tests.
4//! - `SystemClock` uses the OS local time zone (chrono::Local).
5
6use chrono::{Local, Timelike};
7
8pub trait Clock: Send + Sync {
9 /// Minutes since local midnight (00:00..=23:59).
10 fn now_minutes(&self) -> u16;
11}
12
13#[derive(Debug, Default, Clone, Copy)]
14pub struct SystemClock;
15
16impl Clock for SystemClock {
17 fn now_minutes(&self) -> u16 {
18 let now = Local::now();
19 (now.hour() as u16) * 60 + (now.minute() as u16)
20 }
21}
22
23/// Convenience function for callers that don't need dependency injection.
24pub fn system_now_minutes() -> u16 {
25 SystemClock.now_minutes()
26}