From 8d67e16493c903adc9d049141028bc0fff43f8c8 Mon Sep 17 00:00:00 2001 From: GianpaoloBranca Date: Wed, 4 Jan 2023 11:14:06 +0100 Subject: Fixed #33879 -- Improved timesince handling of long intervals. --- tests/template_tests/filter_tests/test_timesince.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/template_tests') diff --git a/tests/template_tests/filter_tests/test_timesince.py b/tests/template_tests/filter_tests/test_timesince.py index 10e4e51d89..d623449e00 100644 --- a/tests/template_tests/filter_tests/test_timesince.py +++ b/tests/template_tests/filter_tests/test_timesince.py @@ -147,6 +147,23 @@ class TimesinceTests(TimezoneTestCase): ) self.assertEqual(output, "1\xa0day") + # Tests for #33879 (wrong results for 11 months + several weeks). + @setup({"timesince19": "{{ earlier|timesince }}"}) + def test_timesince19(self): + output = self.engine.render_to_string( + "timesince19", {"earlier": self.today - timedelta(days=358)} + ) + self.assertEqual(output, "11\xa0months, 3\xa0weeks") + + @setup({"timesince20": "{{ a|timesince:b }}"}) + def test_timesince20(self): + now = datetime(2018, 5, 9) + output = self.engine.render_to_string( + "timesince20", + {"a": now, "b": now + timedelta(days=365) + timedelta(days=364)}, + ) + self.assertEqual(output, "1\xa0year, 11\xa0months") + class FunctionTests(SimpleTestCase): def test_since_now(self): -- cgit v1.2.1