Created
April 4, 2013 12:50
-
-
Save metatoaster/5310106 to your computer and use it in GitHub Desktop.
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 format_reinforcement(delta_t): | |
hours = delta_t.seconds / 3600 | |
days = delta_t.days | |
seconds = delta_t.seconds | |
# Don't ask. Read the test; be happy you don't have to write this. | |
# (WTB something simple like str(delta_t) with more control.) | |
# (Maybe I should just do this in javascript?) | |
return '%(day)s%(hour)s' % { | |
'day': days and '%(days)d day%(dayp)s%(comma)s' % { | |
'days': days, | |
'dayp': days != 1 and 's' or '', | |
'comma': seconds > 3599 and ', ' or '', | |
} or '', | |
'hour': (hours > 0 or days == 0 and hours == 0) | |
and '%(hours)d hour%(hourp)s' % { | |
'hours': hours, | |
'hourp': hours != 1 and 's' or '', | |
} or '', | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment