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/dateformat.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/dateformat.py')
| -rw-r--r-- | django/utils/dateformat.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py index 0afda1850d..d87fb13105 100644 --- a/django/utils/dateformat.py +++ b/django/utils/dateformat.py @@ -14,10 +14,13 @@ Usage: import re import time import calendar +import datetime + from django.utils.dates import MONTHS, MONTHS_3, MONTHS_ALT, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR from django.utils.tzinfo import LocalTimezone from django.utils.translation import ugettext as _ from django.utils.encoding import force_unicode +from django.utils.timezone import is_aware, is_naive re_formatchars = re.compile(r'(?<!\\)([aAbBcdDEfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])') re_escaped = re.compile(r'\\(.)') @@ -115,9 +118,12 @@ class DateFormat(TimeFormat): def __init__(self, dt): # Accepts either a datetime or date object. self.data = dt - self.timezone = getattr(dt, 'tzinfo', None) - if hasattr(self.data, 'hour') and not self.timezone: - self.timezone = LocalTimezone(dt) + self.timezone = None + if isinstance(dt, datetime.datetime): + if is_naive(dt): + self.timezone = LocalTimezone(dt) + else: + self.timezone = dt.tzinfo def b(self): "Month, textual, 3 letters, lowercase; e.g. 'jan'" @@ -218,7 +224,7 @@ class DateFormat(TimeFormat): def U(self): "Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)" - if getattr(self.data, 'tzinfo', None): + if isinstance(self.data, datetime.datetime) and is_aware(self.data): return int(calendar.timegm(self.data.utctimetuple())) else: return int(time.mktime(self.data.timetuple())) |
