Skip to main content

parse_flexible_date

Function parse_flexible_date 

Source
pub fn parse_flexible_date(input: &str) -> Result<FlexibleDate, DateParseError>
Expand description

Parse a date string, trying RFC 2822, long form, ISO 8601 date, then ISO 8601 datetime (spec A4 priority order).

Deterministic and locale-independent: month names come from fixed English tables and no system time is read.

ยงExamples

use ssg::dates::parse_flexible_date;

let dt = parse_flexible_date("Wed, 01 Jul 2026 07:07:07 +0000")
    .expect("RFC 2822 parses");
assert_eq!(dt.to_rfc3339(), "2026-07-01T07:07:07+00:00");

let dt = parse_flexible_date("July 1, 2026").expect("long form parses");
assert_eq!(dt.to_rfc2822(), "Wed, 01 Jul 2026 00:00:00 +0000");

let dt = parse_flexible_date("2026-07-01").expect("ISO date parses");
assert_eq!(dt.to_iso_date(), "2026-07-01");

assert!(parse_flexible_date("not a date").is_err());