From d07e34a182209b3f4271c686789fa7cf6ba65e82 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 3 Jul 2018 12:09:15 +0200 Subject: [PATCH] =?UTF-8?q?Display=20event=20timestamps=20in=20the=20curre?= =?UTF-8?q?nt=20user=E2=80=99s=20time=20zone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calsocial/models.py | 12 ++++++++++++ calsocial/templates/month-view.html | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/calsocial/models.py b/calsocial/models.py index 3445ec6..6717e11 100644 --- a/calsocial/models.py +++ b/calsocial/models.py @@ -197,6 +197,18 @@ class Event(db.Model): return self.__as_tz(self.end_time) + def start_time_for_user(self, user): + """The same timestamp as `start_time`, but in the time zone of `user` + """ + + return self.__as_tz(self.start_time, as_timezone=user.timezone) + + def end_time_for_user(self, user): + """The same timestamp as `end_time`, but in the time zone of `user` + """ + + return self.__as_tz(self.end_time, as_timezone=user.timezone) + def __repr__(self): return f'' diff --git a/calsocial/templates/month-view.html b/calsocial/templates/month-view.html index 1294b77..eee37ff 100644 --- a/calsocial/templates/month-view.html +++ b/calsocial/templates/month-view.html @@ -119,8 +119,7 @@ {{ day.day }} {% for event in calendar.day_events(day, user=current_user) %}
- {{ event.start_time_tz.strftime('%H:%M') }}–{{ event.end_time_tz.strftime('%H:%M') }} - ({{ event.time_zone }}) + {{ event.start_time_for_user(current_user).strftime('%H:%M') }}–{{ event.end_time_for_user(current_user).strftime('%H:%M') }} {{ event.title }}
{% endfor %}