Skip to content

Commit

Permalink
Update to handle AoE for deadlines.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahboyce committed Nov 15, 2023
1 parent 3ea0aea commit 8b9119f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 10 additions & 6 deletions home/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import datetime

from django.conf import settings
from django.core.mail import send_mail
from django.db import models
Expand All @@ -14,10 +16,10 @@
from wagtail.models import Page
from wagtail.snippets.models import register_snippet

from .managers import EventQuerySet
from .managers import SessionMembershipQuerySet
from home.forms import SignUpPage

from .managers import EventQuerySet, SessionMembershipQuerySet


def sign_up_forms(context):
return {
Expand Down Expand Up @@ -195,10 +197,12 @@ def __str__(self):

def is_accepting_applications(self):
"""Determine if the current date is within the application window"""
return (
self.application_start_date.date()
<= timezone.now().date()
<= self.application_end_date.date()
aoe_early_timezone = datetime.timezone(datetime.timedelta(hours=12))
aoe_late_timezone = datetime.timezone(datetime.timedelta(hours=-12))
today_early_aoe = datetime.datetime.now(tz=aoe_early_timezone).date()
today_late_aoe = datetime.datetime.now(tz=aoe_late_timezone).date()
return (self.application_start_date.date() <= today_early_aoe) and (
today_late_aoe <= self.application_end_date.date()
)

def get_absolute_url(self):
Expand Down
9 changes: 9 additions & 0 deletions home/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ def test_is_accepting_applications(self):
with freeze_time("2023-10-15"):
self.assertFalse(self.session.is_accepting_applications())

with freeze_time("2023-10-15 12:00:00"):
# In UTC, so this is the 16th somewhere in the world
self.assertTrue(self.session.is_accepting_applications())

with freeze_time("2023-10-16"):
self.assertTrue(self.session.is_accepting_applications())

with freeze_time("2023-11-15"):
self.assertTrue(self.session.is_accepting_applications())

with freeze_time("2023-11-16"):
# In UTC, so is the 15th still somewhere in the world
self.assertTrue(self.session.is_accepting_applications())

with freeze_time("2023-11-16 12:00:00"):
# No longer 15th AoE
self.assertFalse(self.session.is_accepting_applications())

0 comments on commit 8b9119f

Please sign in to comment.