[util/format] Tests and minor renaming
This commit is contained in:
parent
0f96f2727b
commit
8efa101380
4 changed files with 18 additions and 4 deletions
|
@ -30,19 +30,19 @@ def byte(val, fmt='{:.2f}'):
|
|||
val /= 1024.0
|
||||
return '{}GiB'.format(fmt).format(val*1024.0)
|
||||
|
||||
def duration(duration, shorten=False, suffix=False):
|
||||
def duration(duration, compact=False, unit=False):
|
||||
duration = int(duration)
|
||||
minutes, seconds = divmod(duration, 60)
|
||||
hours, minutes = divmod(minutes, 60)
|
||||
suf = 'm'
|
||||
res = '{:02d}:{:02d}'.format(minutes, seconds)
|
||||
if hours > 0:
|
||||
if shorten:
|
||||
if compact:
|
||||
res = '{:02d}:{:02d}'.format(hours, minutes)
|
||||
else:
|
||||
res = '{:02d}:{}'.format(hours, res)
|
||||
suf = 'h'
|
||||
|
||||
return '{}{}'.format(res, suf if suffix else '')
|
||||
return '{}{}'.format(res, suf if unit else '')
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue