Fixed #33879 -- Fixed wrong results for long intervals.
Added 10 hours to the month duration for intervals longer than 2 months. Adding 10 hours directly to the constant would break other tests, so the fix is added in the algorithm and only affects long intervals.
This commit is contained in:
parent
08303f4f06
commit
6ea0b9383d
|
@ -88,6 +88,9 @@ def timesince(d, now=None, reversed=False, time_strings=None, depth=2):
|
|||
if count == 0:
|
||||
break
|
||||
result.append(avoid_wrapping(time_strings[name] % {"num": count}))
|
||||
# prevent errors in long intervals
|
||||
if name == "month" and count > 2:
|
||||
seconds += 10 * 60 * 60
|
||||
since -= seconds * count
|
||||
current_depth += 1
|
||||
i += 1
|
||||
|
|
|
@ -147,6 +147,14 @@ class TimesinceTests(TimezoneTestCase):
|
|||
)
|
||||
self.assertEqual(output, "1\xa0day")
|
||||
|
||||
# Test 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")
|
||||
|
||||
|
||||
class FunctionTests(SimpleTestCase):
|
||||
def test_since_now(self):
|
||||
|
|
Loading…
Reference in New Issue