Crate whatwg_datetime
source ·Expand description
whatwg-datetime
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 #29.
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,
))
);
License
Licensed under either of
- Apache License, Version 2.0 (
LICENSE-APACHE
or http://www.apache.org/licenses/LICENSE-2.0) - MIT license (
LICENSE-MIT
or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Structs
- A time-zone offset, with a signed number of hours and minutes.
- A proleptic-Gregorian date consisting of a year and a month, with no time-zone or date information.
- A week date consisting of a year and a week number.
- A yearless date, consisting of a gregorian month and a day within the month, without an associated year.
Functions
- Parse a proleptic-Gregorian date, in the format of
YYYY-MM-DD
- Low-level function for parsing an individual date component
- Parse a proleptic-Gregorian date consisting of a date, time, and an optional time-zone offset
- Parse a proleptic-Gregorian date consisting of a date, time, with no time-zone information
- Parse a proleptic-Gregorian date consisting of a year and a month, with no time-zone or date information
- Low-level function for parsing an individual month component
- Parse a specific time containing an hour, minute, and optionally a second, and a fraction of a second
- Low-level function for parsing an individual time component
- Parse a time-zone offset, with a signed number of hours and minutes
- Low-level function for parsing an individual timezone offset component
- Parse a week-year number and a week-number
- Parses a string consisting of a gregorian month and a day within the month, without an associated year
- Low-level function for parsing an individual yearless date component