1use std::time::{SystemTime, UNIX_EPOCH};
2
3use crate::crypto::Timestamped;
4
5pub type TimeGetter = fn() -> Timestamp;
6
7#[derive(Clone, Debug)]
8pub struct Timestamp(pub i64);
9
10pub fn get_time() -> Timestamp {
11 let time = match SystemTime::now().duration_since(UNIX_EPOCH) {
12 Ok(t) => t.as_millis() as i64,
13 Err(e) => -(e.duration().as_millis() as i64),
14 };
15
16 Timestamp(time)
17}
18
19pub fn timestamp<T>(t: T, time_getter: TimeGetter) -> Timestamped<T> {
20 Timestamped { value: t, timestamp: time_getter().0 }
21}