Skip to content

Commit

Permalink
Make current time timezone aware
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j committed Sep 3, 2024
1 parent ab76d40 commit 389f718
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions exceptional_situations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ def situation_sub_type_str(self) -> str:

@property
def is_active(self) -> bool:
now = datetime.now().replace(tzinfo=timezone.get_default_timezone())
if not self.announcements.exists():
return False

start_times_in_future = all(
{a.start_time > timezone.now() for a in self.announcements.all()}
{a.start_time > now for a in self.announcements.all()}
)

# If all start times are in future, return False
if start_times_in_future:
return False
Expand All @@ -84,7 +86,7 @@ def is_active(self) -> bool:
# If end_time is past for all announcements, return True, else False
return any(
{
a.end_time > timezone.now()
a.end_time > now
for a in self.announcements.filter(end_time__isnull=False)
}
)
Expand Down

0 comments on commit 389f718

Please sign in to comment.