mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Account for negative times in timeElapsed.
Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
parent
cbf68e53e3
commit
aa2337791a
@ -77,6 +77,7 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
|
|||||||
be used.
|
be used.
|
||||||
"""
|
"""
|
||||||
ret = []
|
ret = []
|
||||||
|
before = False
|
||||||
def Format(s, i):
|
def Format(s, i):
|
||||||
if i or leadingZeroes or ret:
|
if i or leadingZeroes or ret:
|
||||||
if short:
|
if short:
|
||||||
@ -84,6 +85,12 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
|
|||||||
else:
|
else:
|
||||||
ret.append(format('%n', (i, s)))
|
ret.append(format('%n', (i, s)))
|
||||||
elapsed = int(elapsed)
|
elapsed = int(elapsed)
|
||||||
|
|
||||||
|
# Handle negative times
|
||||||
|
if elapsed < 0:
|
||||||
|
before = True
|
||||||
|
elapsed = -elapsed
|
||||||
|
|
||||||
assert years or weeks or days or \
|
assert years or weeks or days or \
|
||||||
hours or minutes or seconds, 'One flag must be True'
|
hours or minutes or seconds, 'One flag must be True'
|
||||||
if years:
|
if years:
|
||||||
@ -107,10 +114,14 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
|
|||||||
Format('second', secs)
|
Format('second', secs)
|
||||||
if not ret:
|
if not ret:
|
||||||
raise ValueError, 'Time difference not great enough to be noted.'
|
raise ValueError, 'Time difference not great enough to be noted.'
|
||||||
|
result = ''
|
||||||
if short:
|
if short:
|
||||||
return ' '.join(ret)
|
result = ' '.join(ret)
|
||||||
else:
|
else:
|
||||||
return format('%L', ret)
|
result = format('%L', ret)
|
||||||
|
if before:
|
||||||
|
result += ' ago'
|
||||||
|
return result
|
||||||
|
|
||||||
def findBinaryInPath(s):
|
def findBinaryInPath(s):
|
||||||
"""Return full path of a binary if it's in PATH, otherwise return None."""
|
"""Return full path of a binary if it's in PATH, otherwise return None."""
|
||||||
|
Loading…
Reference in New Issue
Block a user