~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/contrib/humanize/templatetags/humanize.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from __future__ import unicode_literals
2
2
import re
3
3
from datetime import date, datetime
 
4
from decimal import Decimal
4
5
 
5
6
from django import template
6
7
from django.conf import settings
35
36
    """
36
37
    if settings.USE_L10N and use_l10n:
37
38
        try:
38
 
            if not isinstance(value, float):
 
39
            if not isinstance(value, (float, Decimal)):
39
40
                value = int(value)
40
41
        except (TypeError, ValueError):
41
42
            return intcomma(value, False)
193
194
            return _('now')
194
195
        elif delta.seconds < 60:
195
196
            return ungettext(
196
 
                'a second ago', '%(count)s seconds ago', delta.seconds
 
197
                # Translators: \\u00a0 is non-breaking space
 
198
                'a second ago', '%(count)s\u00a0seconds ago', delta.seconds
197
199
            ) % {'count': delta.seconds}
198
200
        elif delta.seconds // 60 < 60:
199
201
            count = delta.seconds // 60
200
202
            return ungettext(
201
 
                'a minute ago', '%(count)s minutes ago', count
 
203
                # Translators: \\u00a0 is non-breaking space
 
204
                'a minute ago', '%(count)s\u00a0minutes ago', count
202
205
            ) % {'count': count}
203
206
        else:
204
207
            count = delta.seconds // 60 // 60
205
208
            return ungettext(
206
 
                'an hour ago', '%(count)s hours ago', count
 
209
                # Translators: \\u00a0 is non-breaking space
 
210
                'an hour ago', '%(count)s\u00a0hours ago', count
207
211
            ) % {'count': count}
208
212
    else:
209
213
        delta = value - now
215
219
            return _('now')
216
220
        elif delta.seconds < 60:
217
221
            return ungettext(
218
 
                'a second from now', '%(count)s seconds from now', delta.seconds
 
222
                # Translators: \\u00a0 is non-breaking space
 
223
                'a second from now', '%(count)s\u00a0seconds from now', delta.seconds
219
224
            ) % {'count': delta.seconds}
220
225
        elif delta.seconds // 60 < 60:
221
226
            count = delta.seconds // 60
222
227
            return ungettext(
223
 
                'a minute from now', '%(count)s minutes from now', count
 
228
                # Translators: \\u00a0 is non-breaking space
 
229
                'a minute from now', '%(count)s\u00a0minutes from now', count
224
230
            ) % {'count': count}
225
231
        else:
226
232
            count = delta.seconds // 60 // 60
227
233
            return ungettext(
228
 
                'an hour from now', '%(count)s hours from now', count
 
234
                # Translators: \\u00a0 is non-breaking space
 
235
                'an hour from now', '%(count)s\u00a0hours from now', count
229
236
            ) % {'count': count}