EDTF.DateRange (EDTF v2.0.0)

Copy Markdown View Source

Convert parsed EDTF structs into a {start_date, end_date} tuple of Date.t() values suitable for SQL- or Ecto-style range queries.

The user-facing entry point is EDTF.to_date_range/1, which accepts an EDTF string and delegates here once parsing has succeeded. This module can also be called directly with an already-parsed struct.

Semantics

  • Bounded inputs yield two concrete Date.t() values.
  • Explicitly open inputs (/.., ../, [..2020], [2020..]) yield :unbounded on the open side.
  • Inputs with an unknown bound (1985/, /1985) yield :unknown on that side.
  • Qualifiers (~, ?, %) are ignored — the range uses the nominal date.
  • Unspecified digits (X) forming a contiguous suffix of a component expand to that suffix's span: 19XX → 1900–1999, 2020-1X → Oct–Dec 2020, 2020-12-3X → Dec 30–31 2020. A fully-unknown month or day widens to the whole year or month respectively. Non-suffix unknown digits (X9X2, 2020-X2), a fully-unknown year (XXXX), and suffixes that can't denote a real date (2020-02-3X) return {:error, :unsupported}.
  • Seasons map to month ranges (quarters, quadrimesters, semesters are unambiguous; codes 21–24 are treated as northern-hemisphere; Winter and southern-hemisphere Summer span the year boundary).

Summary

Functions

Convert a parsed EDTF struct (or a parse/1 result tuple) into a {start_date, end_date} tuple.

Functions

to_date_range(error)

Convert a parsed EDTF struct (or a parse/1 result tuple) into a {start_date, end_date} tuple.