Expand description
EDTF (Extended Date/Time Format, ISO 8601-2:2019 Annex A) parsing, validation, level classification, calendar bounds, three-valued temporal relations, value enumeration, and canonical formatting — conformance levels 0–2, complete.
#![no_std] (requires alloc), zero runtime dependencies; JSON support
behind the optional serde feature.
use edtf_core::{Bound, Edtf};
assert!(edtf_core::is_valid("1985-04-12")); // level 0
assert!(edtf_core::is_valid("2004-06~-11")); // level 2 group qualification
assert!(!edtf_core::is_valid("1985-02-30")); // no such calendar day
let d = Edtf::parse("1985-04-12?").unwrap();
assert_eq!(d.level(), 1);
assert!(d.is_uncertain());
// Every expression maps to earliest/latest calendar-day bounds:
let decade = Edtf::parse("156X").unwrap().bounds();
assert_eq!(
format!(
"{}",
match decade.earliest {
Bound::Date(d) => d,
_ => panic!(),
}
),
"1560-01-01"
);
assert_eq!(
format!(
"{}",
match decade.latest {
Bound::Date(d) => d,
_ => panic!(),
}
),
"1569-12-31"
);
// Display renders the canonical (spec-preferred) form:
let messy = Edtf::parse("?2004-?06-?11").unwrap();
assert_eq!(messy.to_string(), "2004-06-11?");
// Three-valued comparison under uncertainty (see docs/spec-notes.md D23):
use edtf_core::Relation;
let a = Edtf::parse("1985~").unwrap();
let b = Edtf::parse("199X").unwrap();
assert_eq!(a.relation(&b).definite(), Some(Relation::Before));
// Enumerate the values an expression denotes (see D24-D29):
let set = Edtf::parse("{1667,1668,1670..1672}").unwrap();
let years: Vec<String> = set.values().unwrap().map(|v| v.to_string()).collect();
assert_eq!(years, ["1667", "1668", "1670", "1671", "1672"]);The grammar and every validation decision are documented with ISO section
citations in docs/spec-notes.md at the repository root.
Structs§
- Bound
Date - A concrete proleptic-Gregorian calendar day used as a bound.
- Bounds
- The earliest and latest calendar day an expression touches.
- Date
- A (possibly qualified, possibly partially unspecified) EDTF date.
- Date
Field - A two-digit month or day slot;
Nonedigits are unspecified (X). - Date
Time - A complete date and time of day (EDTF level 0 only).
- Interval
- A time interval
start/end. - Parse
Error - Error returned when an input is not valid EDTF.
- Qualifier
- Uncertainty (
?), approximation (~), or both (%), per ISO 8601-2 §3.2.6. - Relations
- The modality of every
Relationbetween one pair of expressions, as computed byEdtf::relation. - Set
- A set expression (EDTF level 2).
- Time
- A complete time of day
hh:mm:sswith optional shift (EDTF level 0). - Values
- Lazy iterator over the values an expression denotes; see
Edtf::values. - Year
- A calendar year with optional significant-digit precision and qualification.
Enums§
- Bound
- One side of a
Boundsresult. - Edtf
- Any parsed EDTF expression.
- Interval
Endpoint - One side of a time interval.
- Modality
- How firmly a relation holds across the completions of two expressions.
- Precision
- Precision of a date expression (its lowest specified component).
- Relation
- One of the six coarsened Allen relations between two time regions.
- SetElement
- An element of a set, including
..range notation (ISO 8601-2 §6.3). - SetKind
{…}(all members) vs[…](one member) — ISO 8601-2 §6.1–6.2.- Time
Shift - UTC designator or a numeric shift from UTC.
- Unenumerable
- Why
Edtf::valuescannot enumerate an expression (decisions D24–D25). - Year
Kind - The three syntactic forms a calendar year can take.