Created
June 25, 2013 20:27
-
-
Save dmdavis/5862049 to your computer and use it in GitHub Desktop.
Human-readable time delta.
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
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