[Chicago] OverflowError: days=1002410023; must have magnitude <= 999999999

Michael Tobis mtobis at gmail.com
Wed May 20 20:52:12 CEST 2009

This refers to the datetime module in the standard library, which Lukasz
should have stated explicitly.
>>> d = datetime.timedelta(500000001)
>>> d * 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: days=1000000002; must have magnitude <= 999999999


You need to decide how you are handling fractional days, and it looks like
you will need to manually cast to some other type

The following seems pretty safe and accounts for fractional days. If you
want to account for the fractional seconds, it's a straightforward


totaldays = long(0)
totalseconds = long(0)

for transact in transacts:
    d_time = transact.end_time - transact.start_time
    totaldays += int(d_time.days)
    totalseconds += int(d_time.seconds)

totaldays += totalseconds/SECONDS_PER_DAY

You could probably get away with just accumulating floats, but it would be a
good idea to think very carefully about how that might break that if you
tried it.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20090520/33d92237/attachment.htm>

More information about the Chicago mailing list