Search code examples
pythoninfinitetimedelta

Infinite Timedelta in Python


How can you express an infinite timedelta in Python?

Up to now we use datetime from stdlib, but we could switch, if it is only supported in a third party library.

PostgreSQL does support it. And it would be handy in my case. I want to use it to express an not finished interval.

I could use None, but an infinite timedelta could avoid a lot of conditions (if statements).


Solution

  • I found this: http://initd.org/psycopg/docs/usage.html#infinite-dates-handling

    PostgreSQL can store the representation of an “infinite” date, timestamp, or interval. Infinite dates are not available to Python, so these objects are mapped to date.max, datetime.max, interval.max. Unfortunately the mapping cannot be bidirectional so these dates will be stored back into the database with their values, such as 9999-12-31.

    Short answer: not supported.