Ticket #15921: 15921.1.diff
File 15921.1.diff, 13.8 KB (added by , 14 years ago) |
---|
-
django/contrib/humanize/locale/en/LC_MESSAGES/django.po
diff --git a/django/contrib/humanize/locale/en/LC_MESSAGES/django.mo b/django/contrib/humanize/locale/en/LC_MESSAGES/django.mo index a08dc32..ba05bc9 100644 Binary files a/django/contrib/humanize/locale/en/LC_MESSAGES/django.mo and b/django/contrib/humanize/locale/en/LC_MESSAGES/django.mo differ diff --git a/django/contrib/humanize/locale/en/LC_MESSAGES/django.po b/django/contrib/humanize/locale/en/LC_MESSAGES/django.po index 0e7f3f3..360bdd9 100644
a b msgid "" 4 4 msgstr "" 5 5 "Project-Id-Version: Django\n" 6 6 "Report-Msgid-Bugs-To: \n" 7 "POT-Creation-Date: 2011-05- 07 21:53+0200\n"7 "POT-Creation-Date: 2011-05-16 17:30+0200\n" 8 8 "PO-Revision-Date: 2010-05-13 15:35+0200\n" 9 9 "Last-Translator: Django team\n" 10 10 "Language-Team: English <en@li.org>\n" … … msgstr "" 12 12 "Content-Type: text/plain; charset=UTF-8\n" 13 13 "Content-Transfer-Encoding: 8bit\n" 14 14 15 #: templatetags/humanize.py:2 115 #: templatetags/humanize.py:25 16 16 msgid "th" 17 17 msgstr "" 18 18 19 #: templatetags/humanize.py:2 119 #: templatetags/humanize.py:25 20 20 msgid "st" 21 21 msgstr "" 22 22 23 #: templatetags/humanize.py:2 123 #: templatetags/humanize.py:25 24 24 msgid "nd" 25 25 msgstr "" 26 26 27 #: templatetags/humanize.py:2 127 #: templatetags/humanize.py:25 28 28 msgid "rd" 29 29 msgstr "" 30 30 31 #: templatetags/humanize.py:7 431 #: templatetags/humanize.py:78 32 32 #, python-format 33 33 msgid "%(value).1f million" 34 34 msgid_plural "%(value).1f million" 35 35 msgstr[0] "" 36 36 msgstr[1] "" 37 37 38 #: templatetags/humanize.py:7 538 #: templatetags/humanize.py:79 39 39 #, python-format 40 40 msgid "%(value)s million" 41 41 msgid_plural "%(value)s million" 42 42 msgstr[0] "" 43 43 msgstr[1] "" 44 44 45 #: templatetags/humanize.py:8 045 #: templatetags/humanize.py:84 46 46 #, python-format 47 47 msgid "%(value).1f billion" 48 48 msgid_plural "%(value).1f billion" 49 49 msgstr[0] "" 50 50 msgstr[1] "" 51 51 52 #: templatetags/humanize.py:8 152 #: templatetags/humanize.py:85 53 53 #, python-format 54 54 msgid "%(value)s billion" 55 55 msgid_plural "%(value)s billion" 56 56 msgstr[0] "" 57 57 msgstr[1] "" 58 58 59 #: templatetags/humanize.py: 8659 #: templatetags/humanize.py:90 60 60 #, python-format 61 61 msgid "%(value).1f trillion" 62 62 msgid_plural "%(value).1f trillion" 63 63 msgstr[0] "" 64 64 msgstr[1] "" 65 65 66 #: templatetags/humanize.py: 8766 #: templatetags/humanize.py:91 67 67 #, python-format 68 68 msgid "%(value)s trillion" 69 69 msgid_plural "%(value)s trillion" 70 70 msgstr[0] "" 71 71 msgstr[1] "" 72 72 73 #: templatetags/humanize.py:10 473 #: templatetags/humanize.py:108 74 74 msgid "one" 75 75 msgstr "" 76 76 77 #: templatetags/humanize.py:10 477 #: templatetags/humanize.py:108 78 78 msgid "two" 79 79 msgstr "" 80 80 81 #: templatetags/humanize.py:10 481 #: templatetags/humanize.py:108 82 82 msgid "three" 83 83 msgstr "" 84 84 85 #: templatetags/humanize.py:10 485 #: templatetags/humanize.py:108 86 86 msgid "four" 87 87 msgstr "" 88 88 89 #: templatetags/humanize.py:10 489 #: templatetags/humanize.py:108 90 90 msgid "five" 91 91 msgstr "" 92 92 93 #: templatetags/humanize.py:10 493 #: templatetags/humanize.py:108 94 94 msgid "six" 95 95 msgstr "" 96 96 97 #: templatetags/humanize.py:10 497 #: templatetags/humanize.py:108 98 98 msgid "seven" 99 99 msgstr "" 100 100 101 #: templatetags/humanize.py:10 4101 #: templatetags/humanize.py:108 102 102 msgid "eight" 103 103 msgstr "" 104 104 105 #: templatetags/humanize.py:10 4105 #: templatetags/humanize.py:108 106 106 msgid "nine" 107 107 msgstr "" 108 108 109 #: templatetags/humanize.py:1 27109 #: templatetags/humanize.py:131 110 110 msgid "today" 111 111 msgstr "" 112 112 113 #: templatetags/humanize.py:1 29113 #: templatetags/humanize.py:133 114 114 msgid "tomorrow" 115 115 msgstr "" 116 116 117 #: templatetags/humanize.py:13 1117 #: templatetags/humanize.py:135 118 118 msgid "yesterday" 119 119 msgstr "" 120 120 121 #: templatetags/humanize.py:153 121 #: templatetags/humanize.py:160 122 #, python-format 123 msgctxt "naturaltime" 124 msgid "%(delta)s ago" 125 msgstr "" 126 127 #: templatetags/humanize.py:163 templatetags/humanize.py:185 122 128 msgid "now" 123 129 msgstr "" 124 130 125 #: templatetags/humanize.py:1 55131 #: templatetags/humanize.py:166 126 132 #, python-format 127 msgid " %s secondsago"128 msgid_plural "% s seconds ago"133 msgid "a second ago" 134 msgid_plural "%(count)s seconds ago" 129 135 msgstr[0] "" 130 136 msgstr[1] "" 131 137 132 #: templatetags/humanize.py:1 57138 #: templatetags/humanize.py:171 133 139 #, python-format 134 140 msgid "a minute ago" 135 msgid_plural "% s minutes ago"141 msgid_plural "%(count)s minutes ago" 136 142 msgstr[0] "" 137 143 msgstr[1] "" 138 144 139 #: templatetags/humanize.py:1 59145 #: templatetags/humanize.py:176 140 146 #, python-format 141 147 msgid "an hour ago" 142 msgid_plural "%s hours ago" 148 msgid_plural "%(count)s hours ago" 149 msgstr[0] "" 150 msgstr[1] "" 151 152 #: templatetags/humanize.py:182 153 #, python-format 154 msgctxt "naturaltime" 155 msgid "%(delta)s from now" 156 msgstr "" 157 158 #: templatetags/humanize.py:188 159 #, python-format 160 msgid "a second from now" 161 msgid_plural "%(count)s seconds from now" 162 msgstr[0] "" 163 msgstr[1] "" 164 165 #: templatetags/humanize.py:193 166 #, python-format 167 msgid "a minute from now" 168 msgid_plural "%(count)s minutes from now" 169 msgstr[0] "" 170 msgstr[1] "" 171 172 #: templatetags/humanize.py:198 173 #, python-format 174 msgid "an hour from now" 175 msgid_plural "%(count)s hours from now" 143 176 msgstr[0] "" 144 177 msgstr[1] "" -
django/contrib/humanize/templatetags/humanize.py
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index 560f2a4..7a4defd 100644
a b 1 from django.utils.translation import ungettext, ugettext as _ 2 from d jango.utils.encoding import force_unicode3 from django.utils.formats import number_format 1 import re 2 from datetime import date, datetime, timedelta 3 4 4 from django import template 5 from django.template import defaultfilters6 5 from django.conf import settings 7 from datetime import date, datetime 8 import re 6 from django.template import defaultfilters 7 from django.utils.datetime_safe import datetime, date 8 from django.utils.encoding import force_unicode 9 from django.utils.formats import number_format 10 from django.utils.translation import pgettext, ungettext, ugettext as _ 11 from django.utils.tzinfo import LocalTimezone 12 9 13 10 14 register = template.Library() 11 15 … … def naturalday(value, arg=None): 132 136 return defaultfilters.date(value, arg) 133 137 134 138 @register.filter 135 def naturaltime(value , arg=None):139 def naturaltime(value): 136 140 """ 137 For date and time values shows how many seconds, minutes or hours ago compared to 138 current timestamp returns representing string. Otherwise, returns a string 139 formatted according to settings.DATE_FORMAT 141 For date and time values shows how many seconds, minutes or hours ago 142 compared to current timestamp returns representing string. 140 143 """ 141 144 try: 142 145 value = datetime(value.year, value.month, value.day, value.hour, value.minute, value.second) … … def naturaltime(value, arg=None): 145 148 except ValueError: 146 149 return value 147 150 148 delta = datetime.now() - value 149 if delta.days != 0: 150 value = date(value.year, value.month, value.day) 151 return naturalday(value, arg) 152 elif delta.seconds == 0: 153 return _(u'now') 154 elif delta.seconds < 60: 155 return ungettext(u'%s seconds ago', u'%s seconds ago', delta.seconds) 156 elif delta.seconds / 60 < 60: 157 return ungettext(u'a minute ago', u'%s minutes ago', delta.seconds/60) 158 elif delta.seconds / 60 / 60 < 24: 159 return ungettext(u'an hour ago', u'%s hours ago', delta.seconds/60/60) 160 return naturalday(value, arg) 151 if getattr(value, 'tzinfo', None): 152 now = datetime.now(LocalTimezone(value)) 153 else: 154 now = datetime.now() 155 now = now - timedelta(0, 0, now.microsecond) 156 if value < now: 157 delta = now - value 158 if delta.days != 0: 159 return pgettext( 160 'naturaltime', '%(delta)s ago' 161 ) % {'delta': defaultfilters.timesince(value)} 162 elif delta.seconds == 0: 163 return _(u'now') 164 elif delta.seconds < 60: 165 return ungettext( 166 u'a second ago', u'%(count)s seconds ago', delta.seconds 167 ) % {'count': delta.seconds} 168 elif delta.seconds / 60 < 60: 169 count = delta.seconds / 60 170 return ungettext( 171 u'a minute ago', u'%(count)s minutes ago', count 172 ) % {'count': count} 173 else: 174 count = delta.seconds / 60 / 60 175 return ungettext( 176 u'an hour ago', u'%(count)s hours ago', count 177 ) % {'count': count} 178 else: 179 delta = value - now 180 if delta.days != 0: 181 return pgettext( 182 'naturaltime', '%(delta)s from now' 183 ) % {'delta': defaultfilters.timeuntil(value)} 184 elif delta.seconds == 0: 185 return _(u'now') 186 elif delta.seconds < 60: 187 return ungettext( 188 u'a second from now', u'%(count)s seconds from now', delta.seconds 189 ) % {'count': delta.seconds} 190 elif delta.seconds / 60 < 60: 191 count = delta.seconds / 60 192 return ungettext( 193 u'a minute from now', u'%(count)s minutes from now', count 194 ) % {'count': count} 195 else: 196 count = delta.seconds / 60 / 60 197 return ungettext( 198 u'an hour from now', u'%(count)s hours from now', count 199 ) % {'count': count} -
docs/ref/contrib/humanize.txt
diff --git a/docs/ref/contrib/humanize.txt b/docs/ref/contrib/humanize.txt index 5cacf2b..2f544c7 100644
a b naturaltime 104 104 105 105 For datetime values, returns a string representing how many seconds, 106 106 minutes or hours ago it was -- falling back to a longer date format if the 107 value is more than a day old. 108 109 **Argument:** Date formatting string as described in the :tfilter:`date` tag. 107 value is more than a day old. In case the datetime value is in the future 108 the return value will automatically use an appropriate phrase. 110 109 111 110 Examples (when 'now' is 17 Feb 2007 16:30:00): 112 111 … … Examples (when 'now' is 17 Feb 2007 16:30:00): 116 115 * ``17 Feb 2007 16:25:35`` becomes ``4 minutes ago``. 117 116 * ``17 Feb 2007 15:30:29`` becomes ``an hour ago``. 118 117 * ``17 Feb 2007 13:31:29`` becomes ``2 hours ago``. 119 * ``16 Feb 2007 13:31:29`` becomes ``yesterday``. 120 * Any other day is formatted according to given argument or the 121 :setting:`DATE_FORMAT` setting if no argument is given. 118 * ``16 Feb 2007 13:31:29`` becomes ``1 day ago``. 119 * ``17 Feb 2007 16:30:30`` becomes ``29 seconds from now``. 120 * ``17 Feb 2007 16:31:00`` becomes ``a minute from now``. 121 * ``17 Feb 2007 16:34:35`` becomes ``4 minutes from now``. 122 * ``17 Feb 2007 16:30:29`` becomes ``an hour from now``. 123 * ``17 Feb 2007 18:31:29`` becomes ``2 hours from now``. 124 * ``18 Feb 2007 16:31:29`` becomes ``1 day from now``. 122 125 123 126 .. templatefilter:: ordinal 124 127 -
tests/regressiontests/humanize/tests.py
diff --git a/tests/regressiontests/humanize/tests.py b/tests/regressiontests/humanize/tests.py index bc1bf26..370575a 100644
a b class HumanizeTests(TestCase): 89 89 someday_result, u"I'm not a date value", None) 90 90 self.humanize_tester(test_list, result_list, 'naturalday') 91 91 92 def test_naturaltime(self):93 from django.template import defaultfilters94 now = datetime.now()95 seconds_ago = now - timedelta(seconds=30)96 a_minute_ago = now - timedelta(minutes=1, seconds=30)97 minutes_ago = now - timedelta(minutes=2)98 an_hour_ago = now - timedelta(hours=1, minutes=30, seconds=30)99 hours_ago = now - timedelta(hours=23, minutes=50, seconds=50)100 101 test_list = (now, a_minute_ago, an_hour_ago)102 result_list = (_(u'now'), _(u'a minute ago'), _(u'an hour ago'))103 self.humanize_tester(test_list, result_list, 'naturaltime')104 105 t = Template('{{ seconds_ago|%s }}' % 'naturaltime')106 rendered = t.render(Context(locals())).strip()107 self.assertTrue(u' seconds ago' in rendered)108 109 t = Template('{{ minutes_ago|%s }}' % 'naturaltime')110 rendered = t.render(Context(locals())).strip()111 self.assertTrue(u' minutes ago' in rendered)112 113 t = Template('{{ hours_ago|%s }}' % 'naturaltime')114 rendered = t.render(Context(locals())).strip()115 self.assertTrue(u' hours ago' in rendered)116 117 92 def test_naturalday_tz(self): 118 93 from django.contrib.humanize.templatetags.humanize import naturalday 119 94 … … class HumanizeTests(TestCase): 130 105 131 106 # As 24h of difference they will never be the same 132 107 self.assertNotEqual(naturalday_one, naturalday_two) 108 109 def test_naturaltime(self): 110 now = datetime.now() 111 test_list = [ 112 now, 113 now - timedelta(seconds=1), 114 now - timedelta(seconds=30), 115 now - timedelta(minutes=1, seconds=30), 116 now - timedelta(minutes=2), 117 now - timedelta(hours=1, minutes=30, seconds=30), 118 now - timedelta(hours=23, minutes=50, seconds=50), 119 now - timedelta(days=1), 120 now - timedelta(days=500), 121 now + timedelta(seconds=1), 122 now + timedelta(seconds=30), 123 now + timedelta(minutes=1, seconds=30), 124 now + timedelta(minutes=2), 125 now + timedelta(hours=1, minutes=30, seconds=30), 126 now + timedelta(hours=23, minutes=50, seconds=50), 127 now + timedelta(days=1), 128 now + timedelta(days=500), 129 ] 130 result_list = [ 131 'now', 132 'a second ago', 133 '30 seconds ago', 134 'a minute ago', 135 '2 minutes ago', 136 'an hour ago', 137 '23 hours ago', 138 '1 day ago', 139 '1 year, 4 months ago', 140 'a second from now', 141 '30 seconds from now', 142 'a minute from now', 143 '2 minutes from now', 144 'an hour from now', 145 '23 hours from now', 146 '1 day from now', 147 '1 year, 4 months from now', 148 ] 149 self.humanize_tester(test_list, result_list, 'naturaltime')