ixc / python-edtf

MIT License
52 stars 19 forks source link

Add methods to test dates/other EDTFs against EDTF objects #10

Open cogat opened 7 years ago

cogat commented 7 years ago

At the moment there are basic equal, less-than or greater-than comparison operators that perform simple comparisons. However, each EDTFObject can potentially be a fuzzy, discontinuous range of dates. We can't currently use them for much more than bounding-box calculations.

It would be useful to be able to test a date such as date(1963, 01, 17) against the EDTFObject such as '[1962, 1964] and have it return False, since the date is not in the (discontinuous) range specified.

Something like:

>>> e = parse_edtf("[1962, 1964]")
>>> f = parse_edtf("1963")
>>> f in e 
False
>>> f not in e
True
>>> g = parse_edtf("1962-08-28/1963-08-27")
>>> g in e # f is not wholly contained in e
False
>>> g.overlaps(e)
1 # overlaps the end
>>> e.overlaps(g)
-1 # overlaps the beginning

etc.