Created
October 9, 2013 18:00
-
-
Save squarepegsys/6905476 to your computer and use it in GitHub Desktop.
Trying to get "X days, Y hours, and Z minutes" string with a timedelta. Also, try to use singular when the value is 1
This file contains hidden or 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 get_label(label,val): | |
if val!=1: | |
return label+"s" | |
return label | |
diff = somedate -datetime.now() | |
hours, remainder = divmod(diff.seconds, 3600) | |
minutes, seconds = divmod(remainder, 60) | |
countdown = "{0.days} {1}, {2} {3}, & {4} {5}".format( | |
diff, get_label("day",diff.days), | |
hours, get_label("hour",hours), | |
minutes, get_label("minute",minutes) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment