Skip to main content

sendmock_core/clock/
fixed_clock.rs

1use super::Clock;
2
3#[derive(Debug, Clone, Copy)]
4pub struct FixedClock {
5    fixed_unix_ms: i64,
6}
7
8impl FixedClock {
9    pub fn new(fixed_unix_ms: i64) -> Self {
10        Self { fixed_unix_ms }
11    }
12}
13
14impl Clock for FixedClock {
15    fn now_unix_ms(&self) -> i64 {
16        self.fixed_unix_ms
17    }
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[test]
25    fn always_reads_the_time_it_was_given() {
26        let clock = FixedClock::new(1_767_225_600_000);
27
28        assert_eq!(clock.now_unix_ms(), 1_767_225_600_000);
29        assert_eq!(clock.now_unix_ms(), 1_767_225_600_000);
30    }
31}