Repository: peeringdb/django-peeringdb

Issue:
TIME_ZONE = 'America/Chicago'
The default TIME_ZONE of Django is `America/Chicago`. Combined with stripping the timezone data from the API this causes all timestamps to be saved in the database with a weird offset. At least in PostgreSQL where Django always stores timestamps in UTC.

Adding `TIME_ZONE='UTC'` to `default_settings.py` solves this.

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39?src=pr&el=h1) Report
> Merging [#39](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39?src=pr&el=desc) into [master](https://codecov.io/gh/peeringdb/django-peeringdb/commit/7151c7807927dfb31f3a6d3b4dd6d8adc7d23363?src=pr&el=desc) will **decrease** coverage by `0.18%`.
> The diff coverage is `0%`.

[![Impacted file tree graph](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39/graphs/tree.svg?width=650&token=DHfTekwk1o&height=150&src=pr)](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #39      +/-   ##
==========================================
- Coverage   83.83%   83.65%   -0.19%     
==========================================
  Files          14       14              
  Lines         464      465       +1     
==========================================
  Hits          389      389              
- Misses         75       76       +1
```


| [Impacted Files](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [django\_peeringdb/default\_settings.py](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39/diff?src=pr&el=tree#diff-ZGphbmdvX3BlZXJpbmdkYi9kZWZhdWx0X3NldHRpbmdzLnB5) | `0% <0%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39?src=pr&el=footer). Last update [7151c78...f9c8515](https://codecov.io/gh/peeringdb/django-peeringdb/pull/39?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/django_peeringdb/default_settings.py b/django_peeringdb/default_settings.py
index 23c459d..adea4ad 100644
--- a/django_peeringdb/default_settings.py
+++ b/django_peeringdb/default_settings.py
@@ -40,6 +40,7 @@ LOGGING={
     },
 }
 USE_TZ=False
+TIME_ZONE='UTC'
 # add user defined iso code for Kosovo
 COUNTRIES_OVERRIDE={
     'XK': _('Kosovo'),


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index 4e7062e..7651f6d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,20 +1,8 @@
-from django.conf import settings
-
-
-# lazy init for translations
-_ = lambda s: s
+from django_peeringdb.client_adaptor import setup
 
 
 def pytest_configure():
-
-    settings.configure(
-        INSTALLED_APPS=[
-            'django.contrib.auth',
-            'django.contrib.contenttypes',
-            'django.contrib.admin',
-            'django.contrib.sessions',
-            'django_peeringdb',
-        ],
+    setup.configure(
         DATABASE_ENGINE='django.db.backends.sqlite3',
         DATABASES={
             'default': {
@@ -22,34 +10,6 @@ def pytest_configure():
                 'NAME': ':memory:',
             }
         },
-        DEBUG=False,
-        TEMPLATE_DEBUG=True,
-        LOGGING = {
-            'version': 1,
-            'disable_existing_loggers': False,
-            'handlers': {
-                'stderr': {
-                    'level': 'DEBUG',
-                    'class': 'logging.StreamHandler',
-                    },
-            },
-            'loggers': {
-                '': {
-                    'handlers': ['stderr'],
-                    'level': 'DEBUG',
-                    'propagate': False
-                },
-            },
-        },
-
-        USE_TZ=False,
         PEERINGDB_SYNC_STRIP_TZ=True,
-        # add user defined iso code for Kosovo
-        COUNTRIES_OVERRIDE = {
-            'XK': _('Kosovo'),
-        },
-
-        TABLE_PREFIX='peeringdb_',
-        ABSTRACT_ONLY=False,
         SECRET_KEY='s3cr3t',
     )
diff --git a/tests/test_timezone.py b/tests/test_timezone.py
new file mode 100644
index 0000000..e94e156
--- /dev/null
+++ b/tests/test_timezone.py
@@ -0,0 +1,45 @@
+from django.test import TestCase
+from django.utils.dateparse import parse_datetime
+from django.utils.timezone import make_aware, make_naive, utc
+
+
+class TimeZoneTests(TestCase):
+    """ test time zone handling """
+
+    def test_conversion(self):
+        input = "2020-02-04T20:34:14Z"
+        parsed = parse_datetime(input)
+
+        assert parsed.year == 2020
+        assert parsed.month == 2
+        assert parsed.day == 4
+        assert parsed.hour == 20
+        assert parsed.minute == 34
+        assert parsed.utcoffset().seconds == 0
+
+        stripped = parsed.replace(tzinfo=None)
+
+        assert stripped.year == 2020
+        assert stripped.month == 2
+        assert stripped.day == 4
+        assert stripped.hour == 20
+        assert stripped.minute == 34
+        assert stripped.utcoffset() is None
+
+        aware = make_aware(stripped)
+
+        assert aware.year == 2020
+        assert aware.month == 2
+        assert aware.day == 4
+        assert aware.hour == 20
+        assert aware.minute == 34
+        assert aware.utcoffset().seconds == 0
+
+        naive = make_naive(aware, timezone=utc)
+
+        assert naive.year == 2020
+        assert naive.month == 2
+        assert naive.day == 4
+        assert naive.hour == 20
+        assert naive.minute == 34
+        assert naive.utcoffset() is None