Created
March 4, 2020 19:30
-
-
Save ahmed4end/36097512b0bfd8b129ec3df100e17d65 to your computer and use it in GitHub Desktop.
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
def format_duration(s): | |
dt = [] | |
for b, w in [(60, 'second'), (60, 'minute'), (24, 'hour'), (365, 'day'), (s+1, 'year')]: | |
s, m = divmod(s, b) | |
if m: dt.append('%d %s%s' % (m, w, 's' * (m > 1))) | |
return ' and '.join(', '.join(dt[::-1]).rsplit(', ', 1)) or 'now' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment