summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authorGianpaoloBranca <gianpaolo@protonmail.com>2023-01-04 11:14:06 +0100
committerGitHub <noreply@github.com>2023-01-04 11:14:06 +0100
commit8d67e16493c903adc9d049141028bc0fff43f8c8 (patch)
tree62d4b1215958ba12f8f538c9c6dcad9e30153eed /tests/template_tests
parent99bd5fb4c2d51f7bf8a19b2c12a603ab38b85ec9 (diff)
downloaddjango-8d67e16493c903adc9d049141028bc0fff43f8c8.tar.gz
Fixed #33879 -- Improved timesince handling of long intervals.
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/filter_tests/test_timesince.py17
1 files changed, 17 insertions, 0 deletions
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):