Skip to main content

talk_core/
clock.rs

1/// Injectable clock for Plan 2's live session; Plan 1's pure `select` takes an hour directly.
2#[allow(dead_code)]
3pub trait Clock {
4    fn hour(&self) -> u32; // 0..=23
5}
6
7#[allow(dead_code)]
8pub struct FixedClock(pub u32);
9impl Clock for FixedClock {
10    fn hour(&self) -> u32 { self.0 }
11}
12
13#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14pub enum TimeOfDay { Morning, Day, Evening, Night }
15
16pub fn time_of_day(hour: u32) -> TimeOfDay {
17    match hour {
18        5..=8 => TimeOfDay::Morning,
19        9..=16 => TimeOfDay::Day,
20        17..=20 => TimeOfDay::Evening,
21        _ => TimeOfDay::Night,
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn buckets_the_day() {
31        assert_eq!(time_of_day(7), TimeOfDay::Morning);
32        assert_eq!(time_of_day(23), TimeOfDay::Night);
33    }
34}