Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 607
guettli Avatar asked Jan 20 '15 10:01

guettli


1 Answers

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.

like image 113
guettli Avatar answered Oct 12 '22 19:10

guettli