avoid crashes with too-large numbers

This commit is contained in:
David Rose 2003-05-27 21:02:00 +00:00
parent fdae0a8487
commit ee097fe7a8

View File

@ -551,10 +551,14 @@ def formatElapsedSeconds(seconds):
if seconds < 0: if seconds < 0:
seconds = -seconds seconds = -seconds
sign = '-' sign = '-'
seconds = (int)(seconds)
hours = (int)(seconds / (60 * 60)) # We use math.floor() instead of casting to an int, so we avoid
# problems with numbers that are too large to represent as
# type int.
seconds = math.floor(seconds)
hours = math.floor(seconds / (60 * 60))
if hours > 36: if hours > 36:
days = (int)((hours + 12) / 24) days = math.floor((hours + 12) / 24)
return "%s%d days" % (sign, days) return "%s%d days" % (sign, days)
seconds -= hours * (60 * 60) seconds -= hours * (60 * 60)