pub struct DateField {
pub raw: String,
pub date: Option<Date>,
}Expand description
A frontmatter date field: the scalar exactly as written, plus its parse.
Keeping the raw text lets a consumer round-trip the value and lets the okf-validator crate report which scalar is malformed instead of silently dropping it: the spec’s permissiveness rule means an unparseable date must never make a document unreadable.
Fields§
§raw: StringThe scalar as written in the frontmatter.
date: Option<Date>The parsed date, or None if raw is not a YYYY-MM-DD date.
Implementations§
Source§impl DateField
impl DateField
Sourcepub fn effective_date(&self) -> Option<Date>
pub fn effective_date(&self) -> Option<Date>
The date this field designates, accepting a datetime by taking its date part.
DateField::date is deliberately strict, because the spec asks
stale_after for “an absolute date (YYYY-MM-DD)” and the validator
should report a datetime there as the deviation it is. A comparison still
has to reach a verdict, though, and reading a malformed date as “never
stale” is the dangerous direction: a concept well past its date would
look current. So comparisons use this instead, which matches the
reference implementation’s is_stale (it truncates with
date.fromisoformat(str(raw)[:10])). The written date is used as-is,
without shifting by any UTC offset, exactly as that truncation does.