Repository: fossasia/open-event-server

Issue:
Ticket Email: Timezone of Event Time/Date and Purchase Time/Date should be following event Timezone
The organizer and attendee ticket email show the time and date in UTC instead of the event timezone.

Expected: Always show the emails in the event date and time following the event timezone.

- Currently the Purchase Date and Time are also wrong. They do not actually show the correct UTC time.
- The Purchase Date and Time are should follow the 24 hour format same as the event date/time.


![Screenshot from 2021-09-28 14-51-00](https://user-images.githubusercontent.com/1583873/135091906-c4c75909-5afa-45be-ab80-23dcf71dc429.png)




Discussion:
![image](https://user-images.githubusercontent.com/56963647/135107960-2d84a818-b7cb-422f-b2c6-6c3aaffbfcac.png)
Fix it here too in purchase email
@progmatic-99 please take this up
@progmatic-99 use `astimezone()` in mail.py for event_time. `event_time=event.starts_at.astimezone().strftime("%H:%M (%Z)")` 
and see if this works. Or if you have better way please implement that.
cc: @pc-beast 
@maze-runnar This won't work.

Resolving patch:
diff --git a/app/api/helpers/mail.py b/app/api/helpers/mail.py
--- a/app/api/helpers/mail.py
+++ b/app/api/helpers/mail.py
@@ -2,6 +2,7 @@
 import datetime
 import logging
 import os
+import pytz
 from itertools import groupby
 from typing import Dict, Optional
 
@@ -260,7 +261,9 @@ def send_email_ticket_sales_end_next_week(event, emails):
         )
 
 
-def send_email_session_state_change(email, session, mail_override: Optional[Dict[str, str]] = None):
+def send_email_session_state_change(
+    email, session, mail_override: Optional[Dict[str, str]] = None
+):
     """email for new session"""
     event = session.event
 
@@ -374,15 +377,15 @@ def send_email_announce_event(event, group, emails):
     action = MailType.ANNOUNCE_EVENT
     mail = MAILS[action]
 
-    event_name=event.name
-    group_name=group.name
-    event_date=event.starts_at.strftime('%d %B %Y')
-    event_description=event.description
-    event_url=event.site_link
-    event_location=event.normalized_location
-    event_time=event.starts_at.strftime("%H:%M (%Z)")
-    group_url=group.view_page_link
-    app_name=get_settings()['app_name']
+    event_name = event.name
+    group_name = group.name
+    event_date = event.starts_at.strftime('%d %B %Y')
+    event_description = event.description
+    event_url = event.site_link
+    event_location = event.normalized_location
+    event_time = event.starts_at.strftime("%H:%M (%Z)")
+    group_url = group.view_page_link
+    app_name = get_settings()['app_name']
 
     if len(emails) > 0:
         for email in emails:
@@ -594,9 +597,11 @@ def send_order_purchase_organizer_email(order, recipients):
         site_link=order.event.site_link,
         order_url=order.site_view_link,
         event_date=order.event.starts_at.strftime('%d %B %Y'),
-        event_time=order.event.starts_at.strftime("%H:%M %Z"),
-        purchase_time=order.completed_at,
+        event_time=order.event.starts_at.replace(tzinfo=pytz.timezone('UTC'))
+        .astimezone(pytz.timezone(order.event.timezone))
+        .strftime('%H:%M (%Z%z)'),
         timezone=order.event.timezone,
+        purchase_time=order.completed_at,
         payment_mode=order.payment_mode,
         payment_status=order.status,
         order_amount=order.amount,
diff --git a/app/templates/flask_ext/jinja/filters.py b/app/templates/flask_ext/jinja/filters.py
--- a/app/templates/flask_ext/jinja/filters.py
+++ b/app/templates/flask_ext/jinja/filters.py
@@ -2,7 +2,6 @@
 
 import humanize
 import pytz
-from flask_babel import format_datetime
 from forex_python.converter import CurrencyCodes
 
 from app.api.helpers.utilities import strip_tags
@@ -27,12 +26,12 @@ def money_filter(string):
         return '{:20,.2f}'.format(float(string))
 
     @app.template_filter('datetime')
-    def simple_datetime_display(date, timezone=None, format='MMMM d, yyyy hh:mm a'):
+    def simple_datetime_display(date, timezone=None, format='%B %d, %Y %H:%M (%Z%z)'):
         if not date:
             return ''
         if timezone:
-            date = date.astimezone(pytz.timezone(timezone))
-        return format_datetime(date, format, rebase=False)
+            date = date.replace(tzinfo=pytz.timezone('UTC')).astimezone(pytz.timezone(timezone))
+        return date.strftime(format)
 
     @app.template_filter('date')
     def simple_date_display(date, timezone=None):


Test patch: