Skip to content

Commit

Permalink
Fix format seconds for days
Browse files Browse the repository at this point in the history
Change-Id: Ib7001ff2ed96f16b03fc6a043aca6c7708b9308b
  • Loading branch information
Jeffwhen committed Mar 13, 2023
1 parent 947254a commit 39e3cd7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions python/tpu_perf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def dict_override(a, b):

from datetime import timedelta
def format_seconds(s):
delta = timedelta(seconds=s)
days = s // (24 * 60 * 60)
delta = timedelta(seconds=s % (24 * 60 * 60))
pairs = zip(
[int(v.split('.')[0]) for v in str(delta).split(':')],
['hours', 'minutes', 'seconds'])
return ' '.join(f'{v} {u}' for v, u in pairs if v) or '0 second'
ret = ' '.join(f'{v} {u}' for v, u in pairs if v) or '0 second'
return f'{days} days {ret}' if days else ret

0 comments on commit 39e3cd7

Please sign in to comment.