mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[4.2.x] Fixed #34483 -- Fixed timesince()/timeuntil() with timezone-aware dates and interval less than 1 day.
Regression in8d67e16493. Thanks Lorenzo Peña for the report. Backport of813015d67efrom main
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import zoneinfo
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings, requires_tz_support
|
||||
@@ -241,6 +242,22 @@ class TimesinceTests(TestCase):
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
timesince(self.t, self.t, depth=0)
|
||||
|
||||
@requires_tz_support
|
||||
def test_less_than_a_day_with_zoneinfo(self):
|
||||
now_with_zoneinfo = timezone.now().astimezone(
|
||||
zoneinfo.ZoneInfo(key="Asia/Kathmandu") # UTC+05:45
|
||||
)
|
||||
tests = [
|
||||
(now_with_zoneinfo, "0\xa0minutes"),
|
||||
(now_with_zoneinfo - self.onemicrosecond, "0\xa0minutes"),
|
||||
(now_with_zoneinfo - self.onesecond, "0\xa0minutes"),
|
||||
(now_with_zoneinfo - self.oneminute, "1\xa0minute"),
|
||||
(now_with_zoneinfo - self.onehour, "1\xa0hour"),
|
||||
]
|
||||
for value, expected in tests:
|
||||
with self.subTest(value):
|
||||
self.assertEqual(timesince(value), expected)
|
||||
|
||||
|
||||
@requires_tz_support
|
||||
@override_settings(USE_TZ=True)
|
||||
|
||||
Reference in New Issue
Block a user