diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index 0afda18..8cae2f9 100644
a
|
b
|
from django.utils.tzinfo import LocalTimezone
|
19 | 19 | from django.utils.translation import ugettext as _ |
20 | 20 | from django.utils.encoding import force_unicode |
21 | 21 | |
22 | | re_formatchars = re.compile(r'(?<!\\)([aAbBcdDEfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])') |
| 22 | re_formatchars = re.compile(r'(?<!\\)([aAbBcdDeEfFgGhHiIjlLmMnNoOPrsStTUuwWyYzZ])') |
23 | 23 | re_escaped = re.compile(r'\\(.)') |
24 | 24 | |
25 | 25 | class Formatter(object): |
… |
… |
class DateFormat(TimeFormat):
|
138 | 138 | "Day of the week, textual, 3 letters; e.g. 'Fri'" |
139 | 139 | return WEEKDAYS_ABBR[self.data.weekday()] |
140 | 140 | |
| 141 | def e(self): |
| 142 | "Timezone name if available" |
| 143 | try: |
| 144 | if self.data.tzinfo: |
| 145 | # Have to use tzinfo.tzname and not datetime.tzname |
| 146 | # because datatime.tzname does not expect Unicode |
| 147 | return self.data.tzinfo.tzname(self.data.tzinfo) or "" |
| 148 | except NotImplementedError: |
| 149 | pass |
| 150 | return "" |
| 151 | |
141 | 152 | def E(self): |
142 | 153 | "Alternative month names as required by some locales. Proprietary extension." |
143 | 154 | return MONTHS_ALT[self.data.month] |
… |
… |
class DateFormat(TimeFormat):
|
181 | 192 | "Month abbreviation in Associated Press style. Proprietary extension." |
182 | 193 | return MONTHS_AP[self.data.month] |
183 | 194 | |
| 195 | def o(self): |
| 196 | "ISO 8601 year number matching the ISO week number (W)" |
| 197 | return self.data.isocalendar()[0] |
| 198 | |
184 | 199 | def O(self): |
185 | 200 | "Difference to Greenwich time in hours; e.g. '+0200', '-0430'" |
186 | 201 | seconds = self.Z() |
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 4e5c124..33b1998 100644
a
|
b
|
date
|
1245 | 1245 | |
1246 | 1246 | Formats a date according to the given format. |
1247 | 1247 | |
1248 | | Uses the same format as PHP's ``date()`` function (http://php.net/date) |
1249 | | with some custom extensions. |
| 1248 | Uses a similar format as PHP's ``date()`` function (http://php.net/date) |
| 1249 | with some differences. |
1250 | 1250 | |
1251 | 1251 | Available format strings: |
1252 | 1252 | |
… |
… |
c ISO 8601 format. (Note: unlike others ``2008-01-02T10:30:0
|
1268 | 1268 | d Day of the month, 2 digits with ``'01'`` to ``'31'`` |
1269 | 1269 | leading zeros. |
1270 | 1270 | D Day of the week, textual, 3 letters. ``'Fri'`` |
| 1271 | e Timezone name. Could be in any format, |
| 1272 | or might return an empty string, ``''``, ``'GMT'``, ``'-500'``, ``'US/Eastern'``, etc. |
| 1273 | depending on the datetime. |
1271 | 1274 | E Month, locale specific alternative |
1272 | 1275 | representation usually used for long |
1273 | 1276 | date representation. ``'listopada'`` (for Polish locale, as opposed to ``'Listopad'``) |
… |
… |
M Month, textual, 3 letters. ``'Jan'``
|
1292 | 1295 | n Month without leading zeros. ``'1'`` to ``'12'`` |
1293 | 1296 | N Month abbreviation in Associated Press ``'Jan.'``, ``'Feb.'``, ``'March'``, ``'May'`` |
1294 | 1297 | style. Proprietary extension. |
| 1298 | o ISO-8601 week-numbering year, ``'1999'`` |
| 1299 | corresponding to |
| 1300 | the ISO-8601 week number (W) |
1295 | 1301 | O Difference to Greenwich time in hours. ``'+0200'`` |
1296 | 1302 | P Time, in 12-hour hours, minutes and ``'1 a.m.'``, ``'1:30 p.m.'``, ``'midnight'``, ``'noon'``, ``'12:30 p.m.'`` |
1297 | 1303 | 'a.m.'/'p.m.', with minutes left off |
diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
index 6b79349..9483578 100644
a
|
b
|
def get_filter_tests():
|
345 | 345 | 'date02': (r'{{ d|date }}', {'d': datetime(2008, 1, 1)}, 'Jan. 1, 2008'), |
346 | 346 | #Ticket 9520: Make sure |date doesn't blow up on non-dates |
347 | 347 | 'date03': (r'{{ d|date:"m" }}', {'d': 'fail_string'}, ''), |
| 348 | # ISO date formats |
| 349 | 'date04': (r'{{ d|date:"o" }}', {'d': datetime(2008, 12, 29)}, '2009'), |
| 350 | 'date05': (r'{{ d|date:"o" }}', {'d': datetime(2010, 1, 3)}, '2009'), |
| 351 | # Timezone name |
| 352 | 'date06': (r'{{ d|date:"e" }}', {'d': datetime(2009, 3, 12, tzinfo=FixedOffset(30))}, '+0030'), |
| 353 | 'date07': (r'{{ d|date:"e" }}', {'d': datetime(2009, 3, 12)}, ''), |
348 | 354 | |
349 | 355 | # Tests for #11687 and #16676 |
350 | 356 | 'add01': (r'{{ i|add:"5" }}', {'i': 2000}, '2005'), |