Expand description
Deterministic prose-date → EDTF normalizer (GitHub issue #20).
Real people typing dates into forms need instant, offline, deterministic
normalization — “1980s” → 198X on every keystroke, the same answer every
time. This crate is a bounded pattern grammar over date prose: values are
constructed through the edtf_core model and rendered via its canonical
Display, then re-parsed, so every output is valid, canonical EDTF by
construction. Anything outside the grammar is Outcome::NoMatch — never
a silent guess. Genuinely ambiguous inputs (“12/04/1985”) report every
reading instead of picking one.
Pattern tables are per-language (Language::English and
Language::Russian today); adding a locale means adding one table
struct, not touching the grammar. Every judgement call is a numbered
N-decision in docs/normalize-notes.md, cited from the Note values
attached to results.
use edtf_normalize::{normalize, Outcome};
let Outcome::Normalized(n) = normalize("circa 1920") else { panic!() };
assert_eq!(n.edtf, "1920~");
// "12/04/1985" is DD/MM or MM/DD — the form gets both readings, not a guess.
assert!(matches!(normalize("12/04/1985"), Outcome::Ambiguous(_)));Structs§
- Ambiguous
- A set of plausible readings. Always at least two; the form should ask, not pick.
- Interpretation
- One plausible reading of an ambiguous input.
- Normalized
- A successful, unambiguous normalization.
- Options
- Caller-supplied context. Everything is optional; the defaults never guess.
Enums§
- Language
- Which pattern-table set to match against.
- NoMatch
Reason - Why a
Outcome::NoMatchhappened — the discriminator a bulk-import triage step routes on (N11/N12). - Note
- Why an output looks the way it does. Each variant cites the N-decision in
docs/normalize-notes.mdthat governs it, so a form can explain the conversion to the person typing. - Numeric
Order - Resolution order for all-numeric dates where both readings are plausible.
- Outcome
- The honest return type: a match, several readings, or nothing — never a silent guess.
Functions§
- normalize
- Normalize English date prose with default options.
- normalize_
with - Normalize with explicit
Options(language, numeric order, default century).