Created
May 8, 2016 04:46
-
-
Save Jaxkr/04e811d9c431e8e8fc5313f02d993ff0 to your computer and use it in GitHub Desktop.
Elapsed time to human readable sentence
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
import math | |
def humanize_date_difference(total_seconds): | |
total_seconds = round(total_seconds) | |
if (total_seconds > 3600): | |
hours = math.floor(total_seconds / 3600) | |
minutes = math.floor((total_seconds - (hours * 3600)) / 60) | |
seconds = math.floor((total_seconds - (hours * 3600) - (minutes * 60))) | |
return str(hours) + ' hours, ' + str(minutes) + ' minutes, ' + str(seconds) + ' seconds.' | |
elif (total_seconds > 60): | |
minutes = math.floor(total_seconds / 60) | |
seconds = total_seconds - (60*minutes) | |
return str(minutes) + ' minutes and ' + str(seconds) + ' seconds.' | |
else: | |
return str(total_seconds) + ' seconds.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment