use time::format_description::FormatItem;
use time::macros::format_description;
use time::OffsetDateTime;
const STAMP: &[FormatItem<'static>] =
format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]Z");
pub fn now_rfc3339() -> String {
OffsetDateTime::now_utc()
.format(STAMP)
.unwrap_or_else(|_| "1970-01-01T00:00:00Z".to_string())
}
#[cfg(test)]
mod tests {
use super::*;
use time::format_description::well_known::Rfc3339;
#[test]
fn now_is_parseable_rfc3339() {
let s = now_rfc3339();
assert!(s.ends_with('Z'), "expected Z suffix, got {s}");
assert_eq!(s.len(), 20, "expected second-resolution stamp, got {s}");
assert!(OffsetDateTime::parse(&s, &Rfc3339).is_ok());
}
}