diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-09-25 17:08:31 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-09-25 17:08:31 +0000 |
| commit | 3ef1762cb9f6495c89a5258461cbd9bcbc250557 (patch) | |
| tree | 91f37208539305dabe42c7751509774c9c46ff28 /django/utils/dateformat.py | |
| parent | 482388cd61ee97d8898097fb6777c5d7ca4216af (diff) | |
Fixed #16924 -- Corrected `date` template filter handling of negative (West of UTC) timezone offsets.
The 'O' format specifier output was incorrect. Thanks mrgriscom and Aymeric Augustin.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16903 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/dateformat.py')
| -rw-r--r-- | django/utils/dateformat.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py index f89300938e..0afda1850d 100644 --- a/django/utils/dateformat.py +++ b/django/utils/dateformat.py @@ -182,9 +182,11 @@ class DateFormat(TimeFormat): return MONTHS_AP[self.data.month] def O(self): - "Difference to Greenwich time in hours; e.g. '+0200'" + "Difference to Greenwich time in hours; e.g. '+0200', '-0430'" seconds = self.Z() - return u"%+03d%02d" % (seconds // 3600, (seconds // 60) % 60) + sign = '-' if seconds < 0 else '+' + seconds = abs(seconds) + return u"%s%02d%02d" % (sign, seconds // 3600, (seconds // 60) % 60) def r(self): "RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'" @@ -275,8 +277,10 @@ class DateFormat(TimeFormat): if not self.timezone: return 0 offset = self.timezone.utcoffset(self.data) - # Only days can be negative, so negative offsets have days=-1 and - # seconds positive. Positive offsets have days=0 + # `offset` is a datetime.timedelta. For negative values (to the west of + # UTC) only days can be negative (days=-1) and seconds are always + # positive. e.g. UTC-1 -> timedelta(days=-1, seconds=82800, microseconds=0) + # Positive offsets have days=0 return offset.days * 86400 + offset.seconds def format(value, format_string): |
