diff --git a/Cargo.toml b/Cargo.toml index 9b509513..db61bb2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ axum = { version = "0.8", features = ["ws"] } base64 = "0.22" bcrypt = "0.19" chrono = { version = "0.4", default-features = false, features = [ + "clock", "serde", "std", ] } diff --git a/hive-sh4re/src/wire_time.rs b/hive-sh4re/src/wire_time.rs index 2d952901..50850747 100644 --- a/hive-sh4re/src/wire_time.rs +++ b/hive-sh4re/src/wire_time.rs @@ -18,14 +18,13 @@ pub fn from_secs(secs: i64) -> DateTime { /// Current unix timestamp in seconds — the single definition behind /// every store's `created_at` / `sent_at` / … stamp (this module owns /// the epoch-seconds convention; a dozen local copies of this fn used -/// to float around both binaries). Clamps to 0 on a pre-epoch clock. +/// to float around both binaries). Uses chrono's `clock` feature +/// (already pulled in workspace-wide) instead of hand-rolled +/// `SystemTime` math, consistent with every other timestamp in this +/// module being a `chrono` type. #[must_use] pub fn now_unix() -> i64 { - std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .ok() - .and_then(|d| i64::try_from(d.as_secs()).ok()) - .unwrap_or(0) + Utc::now().timestamp() } #[cfg(test)]