Skip to content

Commit

Permalink
Fix timezone error without pytz #13
Browse files Browse the repository at this point in the history
  • Loading branch information
silentsokolov committed Jan 23, 2018
1 parent ebed7d0 commit a83fbc4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion rangefilter/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import datetime
import django

try:
import pytz
except ImportError:
pytz = None

from collections import OrderedDict

from django import forms
Expand Down Expand Up @@ -38,7 +43,7 @@ def get_timezone(self, request):

@staticmethod
def make_dt_aware(value, timezone):
if settings.USE_TZ:
if settings.USE_TZ and pytz is not None:
default_tz = timezone
if value.tzinfo is not None:
value = default_tz.normalize(value)
Expand Down
8 changes: 8 additions & 0 deletions rangefilter/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

import datetime

try:
import pytz
except ImportError:
pytz = None

from unittest import skipIf

from django.utils import timezone
from django.test import RequestFactory, TestCase
from django.test.utils import override_settings
Expand Down Expand Up @@ -62,6 +69,7 @@ def test_make_dt_aware_without_pytz(self):
self.assertEqual(date.tzinfo, None)
self.assertTrue(timezone.is_naive(date))

@skipIf(pytz is None, "install pytz")
def test_make_dt_aware_with_pytz(self):
local_tz = timezone.get_current_timezone()
now = datetime.datetime.now()
Expand Down
3 changes: 2 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
'default': {'ENGINE': 'django.db.backends.sqlite3'}
},
TEST_RUNNER='django.test.runner.DiscoverRunner',
USE_TZ=True
USE_TZ=True,
TIME_ZONE='UTC',
)

django.setup()
Expand Down

0 comments on commit a83fbc4

Please sign in to comment.