mirror of https://github.com/django/django.git
Fixed #30922 -- Fixed ModelAdmin.date_hierarchy queries with DST changes.
There was an issue where admin date_hierarchy didn't render last day of a month in DST-switch month.
This commit is contained in:
parent
e3d0b4d550
commit
a6cb8ec389
|
@ -173,8 +173,6 @@ class ChangeList:
|
||||||
)
|
)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise IncorrectLookupParameters(e) from e
|
raise IncorrectLookupParameters(e) from e
|
||||||
if settings.USE_TZ:
|
|
||||||
from_date = make_aware(from_date)
|
|
||||||
if day:
|
if day:
|
||||||
to_date = from_date + timedelta(days=1)
|
to_date = from_date + timedelta(days=1)
|
||||||
elif month:
|
elif month:
|
||||||
|
@ -183,6 +181,9 @@ class ChangeList:
|
||||||
to_date = (from_date + timedelta(days=32)).replace(day=1)
|
to_date = (from_date + timedelta(days=32)).replace(day=1)
|
||||||
else:
|
else:
|
||||||
to_date = from_date.replace(year=from_date.year + 1)
|
to_date = from_date.replace(year=from_date.year + 1)
|
||||||
|
if settings.USE_TZ:
|
||||||
|
from_date = make_aware(from_date)
|
||||||
|
to_date = make_aware(to_date)
|
||||||
lookup_params.update({
|
lookup_params.update({
|
||||||
'%s__gte' % self.date_hierarchy: from_date,
|
'%s__gte' % self.date_hierarchy: from_date,
|
||||||
'%s__lt' % self.date_hierarchy: to_date,
|
'%s__lt' % self.date_hierarchy: to_date,
|
||||||
|
|
|
@ -46,6 +46,24 @@ class DateHierarchyTests(TestCase):
|
||||||
make_aware(datetime(2017, 3, 1)),
|
make_aware(datetime(2017, 3, 1)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_bounded_params_with_dst_time_zone(self):
|
||||||
|
tests = [
|
||||||
|
# Northern hemisphere.
|
||||||
|
('Asia/Jerusalem', 3),
|
||||||
|
('Asia/Jerusalem', 10),
|
||||||
|
# Southern hemisphere.
|
||||||
|
('Pacific/Chatham', 4),
|
||||||
|
('Pacific/Chatham', 9),
|
||||||
|
]
|
||||||
|
for time_zone, month in tests:
|
||||||
|
with self.subTest(time_zone=time_zone, month=month):
|
||||||
|
with self.settings(USE_TZ=True, TIME_ZONE=time_zone):
|
||||||
|
self.assertDateParams(
|
||||||
|
{'year': 2019, 'month': month},
|
||||||
|
make_aware(datetime(2019, month, 1)),
|
||||||
|
make_aware(datetime(2019, month + 1, 1)),
|
||||||
|
)
|
||||||
|
|
||||||
def test_invalid_params(self):
|
def test_invalid_params(self):
|
||||||
tests = (
|
tests = (
|
||||||
{'year': 'x'},
|
{'year': 'x'},
|
||||||
|
|
Loading…
Reference in New Issue