whatwg_datetime

Function parse_date_component

Source
pub fn parse_date_component(s: &str, position: &mut usize) -> Option<NaiveDate>
Expand description

Low-level function for parsing an individual date component at a given position

This follows the rules for parsing a date component, per WHATWG HTML Standard § 2.3.5.2 Dates.

Note: This function exposes a lower-level API than parse_date. More than likely, you will want to use parse_date instead.

§Examples

use chrono::NaiveDate;
use whatwg_datetime::parse_date_component;

let mut position = 0usize;
let date = parse_date_component("2011-11-18", &mut position);

assert_eq!(date, NaiveDate::from_ymd_opt(2011, 11, 18));