Add proper time zone support

Until now event timestamps were saved in the server’s time zone.  Now they are saved in UTC,
considering the time zone set by the creator of the event.
This commit is contained in:
2018-07-02 15:07:53 +02:00
parent 26c31bcc04
commit 8a46f3c66a
3 changed files with 95 additions and 3 deletions

View File

@@ -83,5 +83,18 @@ class Event(db.Model):
#: The description of the event
description = db.Column(db.UnicodeText())
def __as_tz(self, timestamp):
from pytz import timezone, utc
return utc.localize(timestamp).astimezone(timezone(self.time_zone))
@property
def start_time_tz(self):
return self.__as_tz(self.start_time)
@property
def end_time_tz(self):
return self.__as_tz(self.end_time)
def __repr__(self):
return f'<Event {self.id} ({self.title}) of {self.user}>'