From f8f535379ae2715d0958a7ecd623db8bf1946963 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Mon, 11 Nov 2019 19:07:35 +0100 Subject: [PATCH] events: Fill ics calendar with TZ-aware datetimes We filled the ics calendar used to produce the ics output with naive datetime specifications without a tiemzone. The ics calendar assument UTC and so the times of the exprted ICS calender were off. The database doesn't containt datetimes, but seperate dates and times which also don't have timezone information. The times are assumend to be the timezone of the server (TIME_ZONE setting in config/settings/base.py). Use astimezone() from pytz library to add time zone information to datetime values handed to the ICS calendar. Acked-By: schrader@molgen.mpg.de --- mpicms/events/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpicms/events/models.py b/mpicms/events/models.py index b11d278..7a28f5b 100644 --- a/mpicms/events/models.py +++ b/mpicms/events/models.py @@ -58,14 +58,14 @@ class Event(BodyMixin, BasePage): @property def start(self): if self.start_time: - return datetime.combine(self.start_date, self.start_time) + return datetime.combine(self.start_date, self.start_time).astimezone() return self.start_date @property def end(self): if self.end_time: date = self.end_date or self.start_date - return datetime.combine(date, self.end_time) + return datetime.combine(date, self.end_time).astimezone() return self.end_date def get_dict(self, request=None):