Repository: fossasia/open-event-server

Issue:
Ticket options are not shown on event page if sale start date is today
Ticketing option is not shown on the event page if the sales start date of the ticket is today.

Expected: Ticket option should be shown on the event page if the sale start time is before now.


Discussion:
@mejariamol would you like to work on this issue?
@SaptakS yes, I will work on this.
@niranjan94 @SaptakS which time zone will server use to check sale start time ??
Internally ... We use UTC ... But we should take into consideration the event's timezone while calculating ticket sales start and end

@niranjan94 @SaptakS It is working correctly for date time input in UTC..
Just wanna be clear about these things..

1. Are we taking date time input from user in UTC or in selected local time zone?

2. And in which form we are storing date time on database ,, UTC or local time zone??

_I could have checked it by myself in the code but thought asking here first would be better way_
1. The user picks a date and time and selects the timezone it is in.
2. It is stored in the database as a _naive datetime_ and the timezone is stored in a separate field. 

> A naive datetime is a datetime that doesn't know its own timezone. It could be in UTC, it could be in US/Eastern, but it doesn't know. All it knows is which date and time that it has. _([more info about naive datetime](http://techblog.thescore.com/2015/11/03/timezones-in-python/))_
@mejariamol Can you please provide steps to recreate this issue, i.e the example data that you filled. I set my timezone to US, and added a ticket which had its start time automatically set according to US. And I was able to access the tickets immediately.
@shubham-padia 

1. choose timezone which is +HHMM to your local timezone .. for example if you are in Asia/Kolkata time zone which is UTC+0530  then choose Pacific/Nauru which is UTC+1200.. 

2. now select sale start time one hour prior to current time in the chosen timezone i.e., UTC+1200.. 

Resolving patch:
diff --git a/app/helpers/data_getter.py b/app/helpers/data_getter.py
--- a/app/helpers/data_getter.py
+++ b/app/helpers/data_getter.py
@@ -733,12 +733,10 @@ def get_locations_of_events():
             return names
 
     @staticmethod
-    def get_sales_open_tickets(event_id, give_all=False):
-        if give_all:
-            tickets = Ticket.query.filter(Ticket.event_id == event_id)
+    def get_sales_open_tickets(event_id, event_timezone='UTC'):
         tickets = Ticket.query.filter(Ticket.event_id == event_id).filter(
-            Ticket.sales_start <= datetime.datetime.now()).filter(
-            Ticket.sales_end >= datetime.datetime.now())
+            Ticket.sales_start <= datetime.datetime.now(pytz.timezone(event_timezone))).filter(
+            Ticket.sales_end >= datetime.datetime.now(pytz.timezone(event_timezone)))
         open_tickets = []
         for ticket in tickets:
             orders = OrderTicket.query.filter(OrderTicket.ticket_id == ticket.id)
diff --git a/app/views/public/event_detail.py b/app/views/public/event_detail.py
--- a/app/views/public/event_detail.py
+++ b/app/views/public/event_detail.py
@@ -71,7 +71,8 @@ def display_event_detail_home(identifier):
     timenow_event_tz = datetime.now(pytz.timezone(event.timezone
                                                   if (event.timezone and event.timezone != '') else 'UTC'))
     module = DataGetter.get_module()
-    tickets = DataGetter.get_sales_open_tickets(event.id, True)
+    tickets = DataGetter.get_sales_open_tickets(event.id, event.timezone
+                                                  if (event.timezone and event.timezone != '') else 'UTC')
 
     '''Sponsor Levels'''
     sponsors = {-1: []}


Test patch: