use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;
pub fn now_rfc3339() -> String {
let now = OffsetDateTime::now_utc()
.replace_nanosecond(0)
.expect("zero nanosecond is valid");
now.format(&Rfc3339)
.expect("UTC datetime formats as RFC 3339")
}
pub fn now_compact() -> String {
let f = time::macros::format_description!("[year][month][day]T[hour][minute][second]Z");
OffsetDateTime::now_utc()
.format(&f)
.expect("UTC datetime formats")
}
#[cfg(test)]
mod tests {
#[test]
fn rfc3339_shape() {
let s = super::now_rfc3339();
assert!(s.ends_with('Z'), "expected UTC zulu suffix: {s}");
assert!(s.len() >= 20);
}
#[test]
fn compact_shape() {
let s = super::now_compact();
assert_eq!(s.len(), 16, "unexpected: {s}");
assert!(s.ends_with('Z'));
}
}