Hi all,
I’d like to propose support for infinite dates, datetimes and timedeltas. They're very useful when you need to model ranges with one or both ends unbounded (e.g. “forever starting from June 15th 2020”).
Without first-class infinite values, you can use None, or you can use the `min` and `max` attributes of Python’s datetime types, or some other arbitrary large values. Using None means you need to implement a path for None, and a path for everything else, and your various infinite values are indistinguishable. Using max/min means comparisons just work, but calculations need special treatment and you’re fundamentally misrepresenting your meaning.
Temporal infinities give the best of both worlds: infinite values that interoperate seamlessly with the built-in types and behave sensibly and predictably. They’re also supported by Postgres!
Usage examples:
>>> from temporal_infinities import *
>>> from datetime import *
>>> DATETIME_POS_INF - datetime(2020, 6, 15)
TIMEDELTA_POS_INF
>>> DATETIME_NEG_INF < date(2020, 6, 15)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'DatetimeInfinity' and 'datetime.date'
>>> DATE_NEG_INF < date(2020, 6, 15)
True
>>> date(2020, 6, 15) + TIMEDELTA_POS_INF
DATE_POS_INF
>>> TIMEDELTA_NEG_INF == TIMEDELTA_NEG_INF
True
My implementation is at
https://github.com/AlexHillAlexHill/temporal-infinities and is designed to be as consistent with the behaviour of floating-point infinities as possible. The expected behaviour of the various types is captured in test_matrix.csv, which is used to produce test cases. Blank cells indicate that a TypeError should be raised. It's tested back to Python 3.4.