Last active
January 10, 2022 01:07
-
-
Save juancarlospaco/d736a4fa5084a0a302e9 to your computer and use it in GitHub Desktop.
Seconds positive integer to friendly human string with precision from seconds to days
This file contains 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 seconds_time_to_human_string(self, time_on_seconds=0): | |
"""Calculate time, with precision from seconds to days.""" | |
minutes, seconds = divmod(int(time_on_seconds), 60) | |
hours, minutes = divmod(minutes, 60) | |
days, hours = divmod(hours, 24) | |
human_time_string = "" | |
if days: | |
human_time_string += "%02d Days " % days | |
if hours: | |
human_time_string += "%02d Hours " % hours | |
if minutes: | |
human_time_string += "%02d Minutes " % minutes | |
human_time_string += "%02d Seconds" % seconds | |
return human_time_string |
Author
juancarlospaco
commented
Jan 11, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment