ending time should round up, not down. also times less than days were not going to display right due to type errors. now they will.

pull/1/head
Andromeda Yelton 2012-06-15 12:06:38 -03:00
parent 12dca9c36d
commit eda96f716b
1 changed files with 13 additions and 3 deletions

View File

@ -139,13 +139,23 @@ def work(request, work_id, action='display'):
countdown = "" countdown = ""
if work.last_campaign_status() == 'ACTIVE': if work.last_campaign_status() == 'ACTIVE':
from math import ceil
time_remaining = campaign.deadline - now() time_remaining = campaign.deadline - now()
'''
we want to round up on all of these; if it's the 3rd and the
campaign ends the 8th, users expect to see 5 days remaining,
not 4 (as an artifact of 4 days 11 hours or whatever)
time_remaining.whatever is an int, so just adding 1 will do
that for us (except in the case where .days exists and both other
fields are 0, which is unlikely enough I'm not defending against it)
'''
if time_remaining.days: if time_remaining.days:
countdown = "in %s days" % time_remaining.days countdown = "in %s days" % str(time_remaining.days + 1)
elif time_remaining.seconds > 3600: elif time_remaining.seconds > 3600:
countdown = "in %s hours" % time_remaining.seconds/3600 countdown = "in %s hours" % str(time_remaining.seconds/3600 + 1)
elif time_remaining.seconds > 60: elif time_remaining.seconds > 60:
countdown = "in %s minutes" % time_remaining.seconds/60 countdown = "in %s minutes" % str(time_remaining.seconds/60 + 1)
else: else:
countdown = "right now" countdown = "right now"
if action == 'preview': if action == 'preview':