From d6ea92085a23990f8a1c2da2ea66cbeca55071cf Mon Sep 17 00:00:00 2001 From: damocles Date: Sat, 1 Aug 2026 17:51:49 +0200 Subject: [PATCH] hive-sh4re: use chrono's clock feature for now_unix instead of hand-rolled SystemTime math --- Cargo.toml | 1 + hive-sh4re/src/wire_time.rs | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) 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)]