fixing ms2runtime, while we're at it
This commit is contained in:
parent
3a8ccbf982
commit
864736c9fc
1 changed files with 14 additions and 26 deletions
|
@ -150,30 +150,18 @@ def ms2runtime(ms, shortenLong=False):
|
||||||
>>> ms2runtime(50000000-20000)
|
>>> ms2runtime(50000000-20000)
|
||||||
'13 hours 53 minutes'
|
'13 hours 53 minutes'
|
||||||
'''
|
'''
|
||||||
seconds = int(ms / 1000)
|
y = int(ms / 31536000000)
|
||||||
years = 0
|
d = int(ms % 31536000000 / 86400000)
|
||||||
days = 0
|
h = int(ms % 86400000 / 3600000)
|
||||||
hours = 0
|
m = int(ms % 3600000 / 60000)
|
||||||
minutes = 0
|
s = int(ms % 60000 / 1000)
|
||||||
if seconds >= 60:
|
if shortenLong and y > 0 or d > 99:
|
||||||
minutes = int(seconds / 60)
|
runtimeString = ("%sy" % y, "%sd" % d, "%sh" % h, "%sm" % m, "%ss" % s)
|
||||||
seconds = seconds % 60
|
|
||||||
if minutes >= 60:
|
|
||||||
hours = int(minutes / 60)
|
|
||||||
minutes = minutes % 60
|
|
||||||
if hours >= 24:
|
|
||||||
days = int(hours / 24)
|
|
||||||
hours = hours % 24
|
|
||||||
if days >= 365:
|
|
||||||
years = int(days / 365)
|
|
||||||
days = days % 365
|
|
||||||
if shortenLong and years > 0 or days > 99:
|
|
||||||
runtimeString = ("%sy" % years, "%sd" % days, "%sh" % hours, "%sm" % minutes, "%ss" % seconds)
|
|
||||||
else:
|
else:
|
||||||
runtimeString = (plural(years, 'year'), plural(days, 'day'),
|
runtimeString = (plural(y, 'year'), plural(d, 'day'),
|
||||||
plural(hours,'hour'), plural(minutes, 'minute'), plural(seconds, 'second'))
|
plural(h,'hour'), plural(m, 'minute'), plural(s, 'second'))
|
||||||
runtimeString = filter(lambda x: not x.startswith('0'), runtimeString)
|
runtimeString = filter(lambda x: not x.startswith('0'), runtimeString)
|
||||||
return " ".join(runtimeString).strip()
|
return ' '.join(runtimeString).strip()
|
||||||
|
|
||||||
def ms2playtime(ms, hours=False):
|
def ms2playtime(ms, hours=False):
|
||||||
'''
|
'''
|
||||||
|
@ -184,10 +172,10 @@ def ms2playtime(ms, hours=False):
|
||||||
>>> ms2playtime(50000000)
|
>>> ms2playtime(50000000)
|
||||||
'13:53:20'
|
'13:53:20'
|
||||||
'''
|
'''
|
||||||
d = math.floor(ms / 86400000)
|
d = int(ms / 86400000)
|
||||||
h = math.floor(ms % 86400000 / 3600000)
|
h = int(ms % 86400000 / 3600000)
|
||||||
m = math.floor(ms % 3600000 / 60000)
|
m = int(ms % 3600000 / 60000)
|
||||||
s = math.floor(ms % 60000 / 1000)
|
s = int(ms % 60000 / 1000)
|
||||||
if d:
|
if d:
|
||||||
playtime= "%d:%02d:%02d:%02d" % (d, h, m, s)
|
playtime= "%d:%02d:%02d:%02d" % (d, h, m, s)
|
||||||
elif h or hours:
|
elif h or hours:
|
||||||
|
|
Loading…
Reference in a new issue