pub fn parse_global_datetime(s: &str) -> Option<DateTime<Utc>>
Expand description

Parse a proleptic-Gregorian date consisting of a date, time, and an optional time-zone offset

This follows the rules for parsing a global datetime string per WHATWG HTML Standard § 2.3.5.7 Global dates and times.

Examples

A global date-time string with a time (hours and minutes):

use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use whatwg_datetime::parse_global_datetime;

assert_eq!(
    parse_global_datetime("2011-11-18T14:54Z"),
    Some(DateTime::<Utc>::from_utc(
        NaiveDateTime::new(
            NaiveDate::from_ymd_opt(2011, 11, 18).unwrap(),
            NaiveTime::from_hms_opt(14, 54, 0).unwrap(),
        ),
        Utc,
    ))
);