Skip to content

Commit

Permalink
events: Fill ics calendar with TZ-aware datetimes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
donald committed Nov 11, 2019
1 parent a70b757 commit f8f5353
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mpicms/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f8f5353

Please sign in to comment.