Created
July 14, 2017 06:42
-
-
Save yassineAlouini/3dd9f60fc37d1bbcef0e6a61677288fd to your computer and use it in GitHub Desktop.
Format seconds to human-readable time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function is extracted from this file: https://github.com/dask/dask/blob/master/dask/diagnostics/progress.py | |
def format_time(t): | |
"""Format seconds into a human readable form. | |
>>> format_time(10.4) | |
'10.4s' | |
>>> format_time(1000.4) | |
'16min 40.4s' | |
""" | |
m, s = divmod(t, 60) | |
h, m = divmod(m, 60) | |
if h: | |
return '{0:2.0f}hr {1:2.0f}min {2:4.1f}s'.format(h, m, s) | |
elif m: | |
return '{0:2.0f}min {1:4.1f}s'.format(m, s) | |
else: | |
return '{0:4.1f}s'.format(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment