hive-sh4re: use chrono's clock feature for now_unix instead of hand-rolled SystemTime math

This commit is contained in:
damocles 2026-08-01 17:51:49 +02:00 committed by mara
commit d6ea92085a
2 changed files with 6 additions and 6 deletions

View file

@ -45,6 +45,7 @@ axum = { version = "0.8", features = ["ws"] }
base64 = "0.22" base64 = "0.22"
bcrypt = "0.19" bcrypt = "0.19"
chrono = { version = "0.4", default-features = false, features = [ chrono = { version = "0.4", default-features = false, features = [
"clock",
"serde", "serde",
"std", "std",
] } ] }

View file

@ -18,14 +18,13 @@ pub fn from_secs(secs: i64) -> DateTime<Utc> {
/// Current unix timestamp in seconds — the single definition behind /// Current unix timestamp in seconds — the single definition behind
/// every store's `created_at` / `sent_at` / … stamp (this module owns /// every store's `created_at` / `sent_at` / … stamp (this module owns
/// the epoch-seconds convention; a dozen local copies of this fn used /// 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] #[must_use]
pub fn now_unix() -> i64 { pub fn now_unix() -> i64 {
std::time::SystemTime::now() Utc::now().timestamp()
.duration_since(std::time::UNIX_EPOCH)
.ok()
.and_then(|d| i64::try_from(d.as_secs()).ok())
.unwrap_or(0)
} }
#[cfg(test)] #[cfg(test)]