use serde::Serialize; use std::time::{SystemTime, UNIX_EPOCH}; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize)] pub struct Timestamp(i64); impl Timestamp { pub fn now() -> Self { let nanos = SystemTime::now() .duration_since(UNIX_EPOCH) .expect("system clock is before the Unix epoch") .as_nanos() as i64; Timestamp(nanos) } #[allow(dead_code)] pub fn from_millis(millis: i64) -> Self { Timestamp(millis * 1_000_000) } pub fn as_millis(&self) -> i64 { self.0 / 1_000_000 } }