Skip to content

Instantly share code, notes, and snippets.

@Jaxkr
Created May 8, 2016 04:46
Show Gist options
  • Save Jaxkr/04e811d9c431e8e8fc5313f02d993ff0 to your computer and use it in GitHub Desktop.
Save Jaxkr/04e811d9c431e8e8fc5313f02d993ff0 to your computer and use it in GitHub Desktop.
Elapsed time to human readable sentence
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