Skip to content

Instantly share code, notes, and snippets.

@dmdavis
Created June 25, 2013 20:27
Show Gist options
  • Save dmdavis/5862049 to your computer and use it in GitHub Desktop.
Save dmdavis/5862049 to your computer and use it in GitHub Desktop.
Human-readable time delta.
from collections import namedtuple
human_delta = namedtuple('human_delta',
['days', 'hours', 'minutes', 'seconds'])
human_delta.__str__ = lambda self: \
'%d days, %d hours, %d minutes, %d seconds' % \
(self.days, self.hours, self.minutes, self.seconds)
def convert_timedelta(duration):
days, seconds = duration.days, duration.seconds
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = (seconds % 60)
return human_delta(days, hours, minutes, seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment