From 389f718fef76e45513b86302d7b1f3986c49d596 Mon Sep 17 00:00:00 2001 From: juuso-j <68938778+juuso-j@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:05:06 +0300 Subject: [PATCH] Make current time timezone aware --- exceptional_situations/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exceptional_situations/models.py b/exceptional_situations/models.py index a4c10d61..894b92e8 100644 --- a/exceptional_situations/models.py +++ b/exceptional_situations/models.py @@ -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 @@ -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) } )