A partial implementation of EDTF format in Python.
See <http://www.loc.gov/standards/datetime/> for the draft specification.
To install
pip install edtf
- Date
- Interval (start/end)
- Uncertain/Approximate dates
- Unspecified dates
- Year exceeding four digits
- Season
- Partial unspecified
- Masked precision
- A rough and ready plain text parser
- Basic conversion to python dates for sorting and range testing
- Times
- Interval (start/end)
- L1 Extended Interval
- partial uncertain/approximate
- one of a set
- multiple dates
- L2 extended Interval
- Year requiring more than 4 digits - Exponential form
>>> from edtf import EDTF
>>> e = EDTF('1898-uu~') # approximately a month in 1898
>>> e.date_earliest() # approximate dates get a bit of padding
datetime.date(1897, 12, 16)
>>> e.date_latest()
datetime.date(1899, 1, 16)
>>> e.sort_date_earliest() # defaults to be at the start of the range
datetime.date(1898, 01, 01)
>>> e.sort_date_latest() # defaults to be at the end of the range
datetime.date(1898, 12, 31)
>>> e.is_interval
False
>>> i = EDTF('1898/1903-08-30') # between 1898 and August 30th 1903
>>> i.earliest_date()
datetime.date(1898, 1, 1)
>>> i.date_latest()
datetime.date(1903, 8, 30)
>>> i.sort_date_earliest()
datetime.date(1898, 01, 01)
>>> i.sort_date_latest()
datetime.date(1903, 08, 30)
>>> i.is_interval
True
>>> p = EDTF.from_natural_text("circa April 1912")
>>> unicode(p)
u'1912-04~'
>>> p.sort_date_earliest()
datetime.date(1912, 4, 01)
>>> p.sort_date_latest()
datetime.date(1912, 4, 30)