off by one

This commit is contained in:
Rolux 2008-07-06 12:22:37 +02:00
commit e52cb82e86

View file

@ -224,18 +224,9 @@ def ms2runtime(ms, shortenLong=False):
>>> ms2runtime(50000000-20000) >>> ms2runtime(50000000-20000)
'13 hours 53 minutes' '13 hours 53 minutes'
''' '''
y = int(ms / 31536000000) if shortenLong and ms > 1000 * 60 * 60 * 24 * 464:
d = int(ms % 31536000000 / 86400000) return formatDuration(ms, verbosity=1, milliseconds=False)
h = int(ms % 86400000 / 3600000) return formatDuration(ms, verbosity=2, milliseconds=False)
m = int(ms % 3600000 / 60000)
s = int(ms % 60000 / 1000)
if shortenLong and y > 0 or d > 99:
runtimeString = ("%sy" % y, "%sd" % d, "%sh" % h, "%sm" % m, "%ss" % s)
else:
runtimeString = (plural(y, 'year'), plural(d, 'day'),
plural(h,'hour'), plural(m, 'minute'), plural(s, 'second'))
runtimeString = filter(lambda x: not x.startswith('0'), runtimeString)
return ' '.join(runtimeString).strip()
def ms2playtime(ms, hours=False): def ms2playtime(ms, hours=False):
# deprecated - use formatDuration # deprecated - use formatDuration
@ -247,17 +238,7 @@ def ms2playtime(ms, hours=False):
>>> ms2playtime(50000000) >>> ms2playtime(50000000)
'13:53:20' '13:53:20'
''' '''
d = int(ms / 86400000) return formatDuration(ms, hours=False, years=False, milliseconds=False)
h = int(ms % 86400000 / 3600000)
m = int(ms % 3600000 / 60000)
s = int(ms % 60000 / 1000)
if d:
playtime= "%d:%02d:%02d:%02d" % (d, h, m, s)
elif h or hours:
playtime= "%02d:%02d:%02d" % (h, m, s)
else:
playtime= "%02d:%02d" % (m, s)
return playtime
def ms2time(ms): def ms2time(ms):
# deprecated - use formatDuration # deprecated - use formatDuration
@ -265,12 +246,7 @@ def ms2time(ms):
>>> ms2time(44592123) >>> ms2time(44592123)
'12:23:12.123' '12:23:12.123'
''' '''
it = int(ms / 1000) return formatDuration(ms, years=False)
ms = ms - it*1000
ss = it % 60
mm = ((it-ss)/60) % 60
hh = ((it-(mm*60)-ss)/3600) % 60
return "%d:%02d:%02d.%03d" % (hh, mm, ss, ms)
def time2ms(timeString): def time2ms(timeString):
''' '''