Skip to main content

parse_rfc3339

Function parse_rfc3339 

Source
pub fn parse_rfc3339(s: &str) -> Option<u64>
Expand description

Seconds since the epoch of YYYY-MM-DDTHH:MM:SSZ, the one shape rfc3339 writes, and its inverse. Anything else is None: a reader that guessed at other shapes would turn a malformed time into a plausible one.

use std::time::{Duration, UNIX_EPOCH};
use majordomus_cli::peers::{parse_rfc3339, rfc3339};
assert_eq!(parse_rfc3339("1970-01-01T00:00:00Z"), Some(0));
let t = UNIX_EPOCH + Duration::from_secs(1_788_000_000);
assert_eq!(parse_rfc3339(&rfc3339(t)), Some(1_788_000_000));
assert_eq!(parse_rfc3339("2026-08-29T10:40:00+02:00"), None);