diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-18 13:01:06 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2011-11-18 13:01:06 +0000 |
| commit | 9b1cb755a28f020e27d4268c214b25315d4de42e (patch) | |
| tree | 2ff0827176f0eb49defa4ce7ce10164f2fc26e86 /django/utils/timesince.py | |
| parent | 01f70349c9ef23d6751437dcd57d2efc193b2661 (diff) | |
Added support for time zones. Thanks Luke Plant for the review. Fixed #2626.
For more information on this project, see this thread:
http://groups.google.com/group/django-developers/browse_thread/thread/cf0423bbb85b1bbf
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17106 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/timesince.py')
| -rw-r--r-- | django/utils/timesince.py | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/django/utils/timesince.py b/django/utils/timesince.py index 369a3e2c01..511acb518a 100644 --- a/django/utils/timesince.py +++ b/django/utils/timesince.py @@ -1,6 +1,6 @@ import datetime -from django.utils.tzinfo import LocalTimezone +from django.utils.timezone import is_aware, utc from django.utils.translation import ungettext, ugettext def timesince(d, now=None): @@ -31,13 +31,10 @@ def timesince(d, now=None): now = datetime.datetime(now.year, now.month, now.day) if not now: - if d.tzinfo: - now = datetime.datetime.now(LocalTimezone(d)) - else: - now = datetime.datetime.now() + now = datetime.datetime.now(utc if is_aware(d) else None) - # ignore microsecond part of 'd' since we removed it from 'now' - delta = now - (d - datetime.timedelta(0, 0, d.microsecond)) + delta = now - d + # ignore microseconds since = delta.days * 24 * 60 * 60 + delta.seconds if since <= 0: # d is in the future compared to now, stop processing. @@ -61,8 +58,5 @@ def timeuntil(d, now=None): the given time. """ if not now: - if getattr(d, 'tzinfo', None): - now = datetime.datetime.now(LocalTimezone(d)) - else: - now = datetime.datetime.now() + now = datetime.datetime.now(utc if is_aware(d) else None) return timesince(now, d) |
