refactor: single now_unix in hive_sh4re::wire_time
replaces 15 per-module copies (now_unix/now_secs) across hive-c0re and hive-ag3nt; wire_time already owns the epoch-seconds convention
This commit is contained in:
parent
d190420946
commit
c84028ddcf
16 changed files with 45 additions and 125 deletions
|
|
@ -15,6 +15,19 @@ pub fn from_secs(secs: i64) -> DateTime<Utc> {
|
|||
DateTime::<Utc>::from_timestamp(secs, 0).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[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)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::{DateTime, Utc};
|
||||
|
|
|
|||
Loading…
Reference in a new issue