mithril_dmq/model/
timestamp.rs

1use std::time::{SystemTime, UNIX_EPOCH};
2
3use mithril_common::StdResult;
4
5/// Provides the current timestamp in seconds since the UNIX epoch.
6#[cfg_attr(test, mockall::automock)]
7pub trait UnixTimestampProvider: Send + Sync {
8    /// Returns the current timestamp in seconds since the UNIX epoch.
9    fn current_timestamp(&self) -> StdResult<u64>;
10}
11
12/// Provides the current timestamp in seconds since the UNIX epoch from the system.
13pub struct SystemUnixTimestampProvider;
14
15impl UnixTimestampProvider for SystemUnixTimestampProvider {
16    fn current_timestamp(&self) -> StdResult<u64> {
17        Ok(SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs())
18    }
19}