summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2019-10-28 11:17:29 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-28 12:28:18 +0100
commit52cb4190720f6ba9dd1cdb9cbd516733b1d4ca58 (patch)
treeeb1edf6d15033b15cb71a896a6436d188571a9da
parent711a7d4d50c1ef194a4a71e68ce7fa38fcb5103f (diff)
Fixed #30918 -- Made timesince()/timeuntil() respect custom time strings for future and the same datetimes.
-rw-r--r--django/utils/timesince.py2
-rw-r--r--tests/utils_tests/test_timesince.py15
2 files changed, 15 insertions, 2 deletions
diff --git a/django/utils/timesince.py b/django/utils/timesince.py
index 23bb5c6da9..3ee70ead21 100644
--- a/django/utils/timesince.py
+++ b/django/utils/timesince.py
@@ -69,7 +69,7 @@ def timesince(d, now=None, reversed=False, time_strings=None):
since = delta.days * 24 * 60 * 60 + delta.seconds
if since <= 0:
# d is in the future compared to now, stop processing.
- return avoid_wrapping(gettext('0 minutes'))
+ return avoid_wrapping(time_strings['minute'] % 0)
for i, (seconds, name) in enumerate(TIMESINCE_CHUNKS):
count = since // seconds
if count != 0:
diff --git a/tests/utils_tests/test_timesince.py b/tests/utils_tests/test_timesince.py
index 3e2c5ce56e..e373b83f43 100644
--- a/tests/utils_tests/test_timesince.py
+++ b/tests/utils_tests/test_timesince.py
@@ -2,8 +2,9 @@ import datetime
import unittest
from django.test.utils import requires_tz_support
-from django.utils import timezone
+from django.utils import timezone, translation
from django.utils.timesince import timesince, timeuntil
+from django.utils.translation import npgettext_lazy
class TimesinceTests(unittest.TestCase):
@@ -74,6 +75,18 @@ class TimesinceTests(unittest.TestCase):
)
self.assertEqual(timesince(self.t, self.t - 4 * self.oneday - 5 * self.oneminute), '0\xa0minutes')
+ def test_second_before_equal_first_humanize_time_strings(self):
+ time_strings = {
+ 'minute': npgettext_lazy('naturaltime-future', '%d minute', '%d minutes'),
+ }
+ with translation.override('cs'):
+ for now in [self.t, self.t - self.onemicrosecond, self.t - self.oneday]:
+ with self.subTest(now):
+ self.assertEqual(
+ timesince(self.t, now, time_strings=time_strings),
+ '0\xa0minut',
+ )
+
@requires_tz_support
def test_different_timezones(self):
""" When using two different timezones. """