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
<https://github.com/AlexHill/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.

Previous discussion:
https://mail.python.org/pipermail/python-ideas/2015-January/031414.html

Thanks for your time!

Alex
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/S4H553FNZPX62RJLHVKCF4JFXBWQWXS6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to