Repository: fossasia/open-event-server

Issue:
Remove validation b/w date offset and timezone
Do not check the date offset and timezone. Many clients, convert date time objects to UTC during serialization. Timezone will be mainly used by Clients for handling date/time of sessions, cfs, and also for displaying to user




Discussion:

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -69,24 +69,6 @@ def validate_timezone(self, data):
                                       "Unknown timezone: '{}'".
                                       format(data['timezone']))
 
-        if 'timezone' in data:
-            offset = timezone(data['timezone']).utcoffset(
-                datetime.strptime('2014-12-01', '%Y-%m-%d')).seconds
-            if 'starts_at' in data:
-                starts_at = data['starts_at'].utcoffset().seconds
-                if offset != starts_at:
-                    raise UnprocessableEntity({'pointer': '/data/attributes/timezone'},
-                                              "timezone: {} does not match with the starts-at "
-                                              "offset {:02}:{:02}".
-                                              format(data['timezone'], starts_at // 3600, starts_at % 3600 // 60))
-            if 'ends_at' in data:
-                ends_at = data['ends_at'].utcoffset().seconds
-                if offset != ends_at:
-                    raise UnprocessableEntity({'pointer': '/data/attributes/timezone'},
-                                              "timezone: {} does not match with the ends-at "
-                                              "offset {:02}:{:02}".
-                                              format(data['timezone'], ends_at // 3600, ends_at % 3600 // 60))
-
     id = fields.Str(dump_only=True)
     identifier = fields.Str(dump_only=True)
     name = fields.Str(required=True)


Test patch:
diff --git a/tests/unittests/api/validation/test_events.py b/tests/unittests/api/validation/test_events.py
--- a/tests/unittests/api/validation/test_events.py
+++ b/tests/unittests/api/validation/test_events.py
@@ -64,33 +64,6 @@ def test_date_db_populate(self):
             data = {}
             EventSchema.validate_date(schema, data, original_data)
 
-    def test_timezone_pass(self):
-        """
-        Events Validate Timezone - Tests if the function runs without an exception
-        :return:
-        """
-        schema = EventSchema()
-        data = {
-            'starts_at': datetime(2003, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
-            'ends_at': datetime(2003, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
-            'timezone': 'UTC'
-        }
-        EventSchema.validate_timezone(schema, data)
-
-    def test_timezone_fail(self):
-        """
-        Events Validate Timezone - Tests if the function raises an exception
-        :return:
-        """
-        schema = EventSchema()
-        data = {
-            'starts_at': datetime(2003, 8, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
-            'ends_at': datetime(2003, 9, 4, 12, 30, 45).replace(tzinfo=timezone('UTC')),
-            'timezone': 'Asia/Kolkata'
-        }
-        with self.assertRaises(UnprocessableEntity):
-            EventSchema.validate_timezone(schema, data)
-
 
 if __name__ == '__main__':
     unittest.main()