From 3cf2c15d3dbcc7cc167cc1dd562711d0e141e39e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 3 Jul 2018 12:03:54 +0200 Subject: [PATCH] [Refactor] Refactor Event.__as_tz() so it accepts a timezone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now it could only convert to the event’s timezone --- calsocial/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/calsocial/models.py b/calsocial/models.py index 3a813e9..2975732 100644 --- a/calsocial/models.py +++ b/calsocial/models.py @@ -110,10 +110,12 @@ class Event(db.Model): #: The description of the event description = db.Column(db.UnicodeText()) - def __as_tz(self, timestamp): - from pytz import timezone, utc + def __as_tz(self, timestamp, as_timezone=None): + from pytz import timezone, UTC - return utc.localize(timestamp).astimezone(timezone(self.time_zone)) + utc_timestamp = UTC.localize(timestamp) + + return utc_timestamp.astimezone(as_timezone or timezone(self.time_zone)) @property def start_time_tz(self):