fx_utils/time.rs
1//! Time utilities for high-precision timestamps
2
3use chrono::{DateTime, Utc};
4use std::time::{SystemTime, UNIX_EPOCH};
5
6/// Get current timestamp in nanoseconds since epoch
7pub fn now_nanos() -> u64 {
8 SystemTime::now()
9 .duration_since(UNIX_EPOCH)
10 .expect("Time went backwards")
11 .as_nanos() as u64
12}
13
14/// Get current timestamp in microseconds since epoch
15pub fn now_micros() -> u64 {
16 SystemTime::now()
17 .duration_since(UNIX_EPOCH)
18 .expect("Time went backwards")
19 .as_micros() as u64
20}
21
22/// Get current UTC datetime
23pub fn now_utc() -> DateTime<Utc> {
24 Utc::now()
25}