Skip to main content

Module dates

Module dates 

Source
Expand description

Flexible, dependency-free date parsing shared by the feed and sitemap post-processing plugins.

Issue #586 / v0.0.47 plan §2 item 1.4 (spec A4): the native rss.rs, atom.rs, json_feed.rs, news_sitemap.rs, and sitemap.rs plugins each used to parse dates independently, and only understood RFC 2822. Front matter written as July 1, 2026 or 2026-07-01 fell through and produced the upstream 'day' component could not be parsed warning spam. This module is the single parsing chain they all share.

parse_flexible_date accepts, in priority order:

  1. RFC 2822 — Wed, 01 Jul 2026 07:07:07 +0000 (weekday optional and not verified, matching the lenient behaviour the plugins already relied on; seconds optional; named zones from the RFC 2822 obsolete table accepted).
  2. Long form — July 1, 2026 and 1 July 2026 (full month names or three-letter abbreviations; midnight UTC assumed).
  3. ISO 8601 date — 2026-07-01 (midnight UTC assumed).
  4. ISO 8601 datetime — 2026-07-01T07:07:07Z, with Z, ±hh:mm, or ±hhmm offsets (UTC assumed when absent).

Everything is hand-rolled — month-name tables, leap-year aware day validation, timezone offset parsing — so no new dependency is introduced. Parsing is fully deterministic: no locale lookups and no system-time reads.

The output side offers the exact shapes the plugins emit today: FlexibleDate::to_rfc2822 for RSS <pubDate>, FlexibleDate::to_rfc3339 / FlexibleDate::to_w3c_date for Atom <updated> and the news-sitemap <news:publication_date>, and FlexibleDate::to_iso_date for sitemap <lastmod>.

Structs§

DateParseError
Error for input that matched none of the supported date formats.
FlexibleDate
A parsed calendar date-time with a fixed UTC offset.

Enums§

DateFormat
The input format that parse_flexible_date matched.

Constants§

ATTEMPTED_FORMATS
The formats attempted by parse_flexible_date, in priority order.

Functions§

days_in_month
Number of days in the given month of the given year (leap-year aware). Returns 0 for an out-of-range month.
is_leap_year
true for Gregorian leap years (divisible by 4, except centuries not divisible by 400).
parse_flexible_date
Parse a date string, trying RFC 2822, long form, ISO 8601 date, then ISO 8601 datetime (spec A4 priority order).