Skip to content

Commit

Permalink
Fix django 4.0 timezone #71
Browse files Browse the repository at this point in the history
  • Loading branch information
silentsokolov committed Dec 15, 2021
1 parent 9e2774c commit a29c6d1
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions rangefilter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
except ImportError:
csp = None

try:
import zoneinfo
except ImportError:
try:
from backports import zoneinfo
except ImportError:
zoneinfo = None

from collections import OrderedDict

from django import forms
Expand Down Expand Up @@ -104,13 +112,16 @@ def _get_default_values(request, model_admin, field_path):
return None, None

@staticmethod
def make_dt_aware(value, timezone):
if settings.USE_TZ and pytz is not None:
default_tz = timezone
if value.tzinfo is not None:
value = default_tz.normalize(value)
else:
value = default_tz.localize(value)
def make_dt_aware(value, tzname):
if django.VERSION <= (4, 0, 0):
if settings.USE_TZ and pytz is not None:
default_tz = tzname
if value.tzinfo is not None:
value = default_tz.normalize(value)
else:
value = default_tz.localize(value)
else:
value = value.replace(tzinfo=tzname)
return value

def choices(self, cl):
Expand Down

0 comments on commit a29c6d1

Please sign in to comment.