Skip to main content

rightkit_agent_engine_protocol/
time.rs

1use std::time::{SystemTime, UNIX_EPOCH};
2
3pub fn now_iso() -> String {
4    let secs = SystemTime::now()
5        .duration_since(UNIX_EPOCH)
6        .map(|d| d.as_secs())
7        .unwrap_or(0);
8    epoch_seconds_to_iso(secs)
9}
10
11/// RFC 3339 UTC text (`YYYY-MM-DDTHH:MM:SSZ`) for `secs` since the Unix epoch.
12fn epoch_seconds_to_iso(secs: u64) -> String {
13    i64::try_from(secs)
14        .ok()
15        .and_then(|secs| rightkit_time::DateTime::from_unix(secs, 0))
16        .map(|dt| dt.format_rfc3339())
17        .unwrap_or_default()
18}