What is happening here?
This expected:
>>> datetime.min - timedelta(days=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: date value out of range
Unexpected:
>>> datetime.min - timedelta(days=2)
datetime.datetime(1, 0, 255, 0, 0)
>>> datetime.min > (datetime.min - timedelta(days=2))
True
In python, what do these values mean when you subtract from datetime.min? What dates do they represent? Why do some cases not trigger an OverflowError?
Because you need to upgrade to Python 2.6 or later, which fixed this bug.
$ python2.5 -c 'import datetime; print(datetime.datetime.min - datetime.timedelta(days=2))'
0001-00-255 00:00:00
$ python2.6 -c 'import datetime; print(datetime.datetime.min - datetime.timedelta(days=2))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
OverflowError: date value out of range
$ python2.7 -c 'import datetime; print(datetime.datetime.min - datetime.timedelta(days=2))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
OverflowError: date value out of range
$ python3.3 -c 'import datetime; print(datetime.datetime.min - datetime.timedelta(days=2))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
OverflowError: date value out of range
Do you need someone to track down the bug number, patch, and python-dev discussion, or is that enough information for you?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With