Crate whatwg_datetime

Source
Expand description

A Rust crate for parsing the datetime microsyntax, as defined by the WHATWG HTML Standard.

§Install

cargo add whatwg-datetime

§Usage

This library currently implements 8 of the 9 datetime formats defined by the WHATWG HTML Standard. The only format not implemented is the duration format, which is tracked in issue #23.

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

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

Structs§

TimeZoneOffset
A time-zone offset, with a signed number of hours and minutes.
YearMonth
A proleptic-Gregorian date consisting of a year and a month, with no time-zone or date information.
YearWeek
A week date consisting of a year and a week number.
YearlessDate
A yearless date, consisting of a gregorian month and a day within the month, without an associated year.

Functions§

parse_date
Parse a proleptic-Gregorian date, in the format of YYYY-MM-DD
parse_date_component
Low-level function for parsing an individual date component at a given position
parse_global_datetime
Parse a proleptic-Gregorian date consisting of a date, time, and an optional time-zone offset
parse_local_datetime
Parse a proleptic-Gregorian date consisting of a date, time, with no time-zone information
parse_month
Parse a proleptic-Gregorian date consisting of a year and a month, with no time-zone or date information
parse_month_component
Low-level function for parsing an individual month component at a given position
parse_time
Parse a specific time containing an hour, minute, and optionally a second, and a fraction of a second
parse_time_component
Low-level function for parsing an individual time component at a given position
parse_timezone_offset
Parse a time-zone offset, with a signed number of hours and minutes
parse_timezone_offset_component
Low-level function for parsing an individual timezone offset component at a given position
parse_week
Parse a week-year number and a week-number
parse_yearless_date
Parses a string consisting of a gregorian month and a day within the month, without an associated year
parse_yearless_date_component
Low-level function for parsing an individual yearless date component at a given position

Type Aliases§

ParseComponentFn
ParseStringFn