cometbft_light_client/components/
clock.rs1use std::convert::TryInto;
4
5use time::OffsetDateTime;
6
7use crate::verifier::types::Time;
8
9pub trait Clock: Send + Sync {
11 fn now(&self) -> Time;
13}
14
15#[derive(Copy, Clone, Debug)]
17pub struct SystemClock;
18impl Clock for SystemClock {
19 fn now(&self) -> Time {
20 OffsetDateTime::now_utc()
21 .try_into()
22 .expect("system clock produces invalid time")
23 }
24}
25
26#[derive(Copy, Clone, Debug)]
27pub struct FixedClock {
28 now: Time,
29}
30
31impl FixedClock {
32 pub fn new(now: Time) -> Self {
33 Self { now }
34 }
35}
36
37impl Clock for FixedClock {
38 fn now(&self) -> Time {
39 self.now
40 }
41}