Skip to content

Commit

Permalink
Fixes #443, #384. Timezone aware due date fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlemann committed Jan 10, 2018
1 parent e56737b commit af0e8e9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions schools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class SchoolProfile(models.Model):
def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
if not self.created_at:
self.created_at = datetime.datetime.now()
self.created_at = timezone.now()
super(SchoolProfile, self).save(force_insert=force_insert, force_update=force_update,
using=using, update_fields=update_fields)

Expand All @@ -301,7 +301,8 @@ def due_date(self):
self.created_at > timezone.datetime(2017, 12, 30, tzinfo=tz)):
hard_coded_due_date = timezone.datetime(2018, 1, 15, tzinfo=tz)
return hard_coded_due_date.date()
return (self.created_at + datetime.timedelta(30)).date()
due_dt = (self.created_at + datetime.timedelta(30))
return due_dt.astimezone(timezone.get_current_timezone()).date()

def percent_complete(self):
field_names = self.__class__._meta.get_all_field_names()
Expand All @@ -314,8 +315,9 @@ def percent_complete(self):
return float('%.2f' % (filled_fields/len(field_names)*100))

def overdue(self):
tomorrow = (timezone.now() + datetime.timedelta(days=2)).date()
return False # HACK
tomorrow = (timezone.now() + datetime.timedelta(days=1))
tomorrow = tomorrow.astimezone(timezone.get_current_timezone())
tomorrow = tomorrow.date()
return self.due_date() < tomorrow

def url(self):
Expand Down

0 comments on commit af0e8e9

Please sign in to comment.