summaryrefslogtreecommitdiff
path: root/django/utils/dateformat.py
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2012-02-09 18:57:31 +0000
committerJannis Leidel <jannis@leidel.info>2012-02-09 18:57:31 +0000
commita6b6c6e17129379fa1f9ffce1ed7eaaa5d6f1127 (patch)
tree090663b15fce2c07992d1fd5afdd22c58408cf21 /django/utils/dateformat.py
parente445b66fd8a2b5e931debad3c920be1345871ad9 (diff)
Fixed #16416 -- Added two new date formatting options for timezones and ISO week numbers. Thanks, poirier.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17473 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/dateformat.py')
-rw-r--r--django/utils/dateformat.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index d87fb13105..81c2d87f91 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -22,7 +22,7 @@ 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_formatchars = re.compile(r'(?<!\\)([aAbBcdDeEfFgGhHiIjlLmMnNoOPrsStTUuwWyYzZ])')
re_escaped = re.compile(r'\\(.)')
class Formatter(object):
@@ -144,6 +144,17 @@ class DateFormat(TimeFormat):
"Day of the week, textual, 3 letters; e.g. 'Fri'"
return WEEKDAYS_ABBR[self.data.weekday()]
+ def e(self):
+ "Timezone name if available"
+ try:
+ if self.data.tzinfo:
+ # Have to use tzinfo.tzname and not datetime.tzname
+ # because datatime.tzname does not expect Unicode
+ return self.data.tzinfo.tzname(self.data) or ""
+ except NotImplementedError:
+ pass
+ return ""
+
def E(self):
"Alternative month names as required by some locales. Proprietary extension."
return MONTHS_ALT[self.data.month]
@@ -187,6 +198,10 @@ class DateFormat(TimeFormat):
"Month abbreviation in Associated Press style. Proprietary extension."
return MONTHS_AP[self.data.month]
+ def o(self):
+ "ISO 8601 year number matching the ISO week number (W)"
+ return self.data.isocalendar()[0]
+
def O(self):
"Difference to Greenwich time in hours; e.g. '+0200', '-0430'"
seconds = self.Z()