orbok_core/timeutil.rs
1//! UTC timestamp helpers (external design ยง9.3: ISO-8601 UTC strings).
2
3use time::OffsetDateTime;
4use time::format_description::well_known::Rfc3339;
5
6/// Current UTC time as an RFC 3339 / ISO-8601 string, e.g.
7/// `2026-06-06T12:34:56.789Z`.
8pub fn now_iso8601() -> String {
9 OffsetDateTime::now_utc()
10 .format(&Rfc3339)
11 .expect("RFC 3339 formatting of the current UTC time cannot fail")
12}
13
14/// Convert a [`std::time::SystemTime`] (e.g. file mtime) to RFC 3339.
15pub fn system_time_iso8601(t: std::time::SystemTime) -> String {
16 OffsetDateTime::from(t)
17 .format(&Rfc3339)
18 .unwrap_or_else(|_| String::from("1970-01-01T00:00:00Z"))
19}