summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authornessita <124304+nessita@users.noreply.github.com>2023-04-13 13:16:33 -0300
committerNatalia <124304+nessita@users.noreply.github.com>2023-04-13 13:20:16 -0300
commita3c14ea61b7b0e91ff646dfe75850d918ef7e478 (patch)
treecbc98f5c0bc7f24a58bbfa0e4b9dba63d249b67f /tests
parent791407fef16faa4da6fe2247c24a9055037dd5dd (diff)
[4.2.x] Fixed #34483 -- Fixed timesince()/timeuntil() with timezone-aware dates and interval less than 1 day.
Regression in 8d67e16493c903adc9d049141028bc0fff43f8c8. Thanks Lorenzo Peña for the report. Backport of 813015d67e2557fa859a07930a9becec4e5f64a0 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/utils_tests/test_timesince.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/utils_tests/test_timesince.py b/tests/utils_tests/test_timesince.py
index 242e582f9e..d54fce2be6 100644
--- a/tests/utils_tests/test_timesince.py
+++ b/tests/utils_tests/test_timesince.py
@@ -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)