Skip to content

Commit 5ceea8c

Browse files
committed
feat(dmq): add a Unix timestamp provider trait
1 parent 7461632 commit 5ceea8c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
mod builder;
22
mod message;
3+
mod timestamp;
34

45
pub use builder::*;
56
pub use message::*;
7+
pub use timestamp::*;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::time::{SystemTime, UNIX_EPOCH};
2+
3+
use mithril_common::StdResult;
4+
5+
/// Provides the current timestamp in seconds since the UNIX epoch.
6+
#[cfg_attr(test, mockall::automock)]
7+
pub 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.
13+
pub struct SystemUnixTimestampProvider;
14+
15+
impl UnixTimestampProvider for SystemUnixTimestampProvider {
16+
fn current_timestamp(&self) -> StdResult<u64> {
17+
Ok(SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs())
18+
}
19+
}

0 commit comments

Comments
 (0)