Skip to content

Commit

Permalink
Add optional padding for times.
Browse files Browse the repository at this point in the history
  • Loading branch information
matham committed Feb 10, 2022
1 parent 4a6ce00 commit 275da6f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion base_kivy_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'yaml_dumps', 'yaml_loads', 'get_yaml')


def pretty_time(seconds):
def pretty_time(seconds, pad=False):
'''Returns a nice representation of a time value.
:Parameters:
Expand All @@ -33,6 +33,14 @@ def pretty_time(seconds):
s, ms = divmod(seconds, 10)
m, s = divmod(s, 60)
h, m = divmod(m, 60)
if pad:
if h:
return '{0:0>2d}:{1:0>2d}:{2:0>2d}.{3:d}'.format(h, m, s, ms)
elif m:
return '00:{0:0>2d}:{1:0>2d}.{2:d}'.format(m, s, ms)
else:
return '00:00:{0:0>2d}.{1:d}'.format(s, ms)

if h:
return '{0:d}:{1:d}:{2:d}.{3:d}'.format(h, m, s, ms)
elif m:
Expand Down

0 comments on commit 275da6f

Please sign in to comment.