14
src/time.rs
Normal file
14
src/time.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user