forked from gergely/calendar-social
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:
@@ -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}>'
|
||||
|
Reference in New Issue
Block a user