Skip to main content

Crate edtf_core

Crate edtf_core 

Source
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§

BoundDate
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.
DateField
A two-digit month or day slot; None digits are unspecified (X).
DateTime
A complete date and time of day (EDTF level 0 only).
Interval
A time interval start/end.
ParseError
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 Relation between one pair of expressions, as computed by Edtf::relation.
Set
A set expression (EDTF level 2).
Time
A complete time of day hh:mm:ss with 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 Bounds result.
Edtf
Any parsed EDTF expression.
IntervalEndpoint
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.
TimeShift
UTC designator or a numeric shift from UTC.
Unenumerable
Why Edtf::values cannot enumerate an expression (decisions D24–D25).
YearKind
The three syntactic forms a calendar year can take.

Functions§

is_valid
Returns true if input is a valid EDTF string (levels 0–2).
level
Parse input and return its minimum EDTF conformance level (0, 1 or 2), or None if it is not valid EDTF.