whatwg_datetime

Function parse_yearless_date

Source
pub fn parse_yearless_date(s: &str) -> Option<YearlessDate>
Expand description

Parses a string consisting of a gregorian month and a day within the month, without an associated year

This follows the rules for parsing a yearless date string per WHATWG HTML Standard § 2.3.5.3 Yearless dates.

§Examples

use whatwg_datetime::{parse_yearless_date, YearlessDate};

assert_eq!(parse_yearless_date("11-18"), YearlessDate::new_opt(11, 18));
assert_eq!(parse_yearless_date("02-29"), YearlessDate::new_opt(2, 29));
assert_eq!(parse_yearless_date("02-30"), None); // February never has 30 days
assert_eq!(parse_yearless_date("04-31"), None); // April only has 30 days
assert_eq!(parse_yearless_date("13-01"), None);