Files
herocoordinator/src/time.rs
Lee Smet acf875ed33 Add basic models
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
2025-08-20 14:04:08 +02:00

15 lines
482 B
Rust

use std::time::{SystemTime, UNIX_EPOCH};
/// A timestamp since the unix epoch
pub type Timestamp = i64;
/// Get the current system timestamp
pub fn current_timestamp() -> Timestamp {
let now = SystemTime::now();
// A duration is always positive so this returns an unsigned integer, while a timestamp can
// predate the unix epoch so we must cast to a signed integer.
now.duration_since(UNIX_EPOCH)
.expect("Time moves forward")
.as_secs() as i64
}