Ticket #16416: 16416.diff

File 16416.diff, 4.6 KB (added by Dan Poirier, 7 years ago)
  • django/utils/dateformat.py

    diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
    index 0afda18..8cae2f9 100644
    a b from django.utils.tzinfo import LocalTimezone 
    1919from django.utils.translation import ugettext as _
    2020from django.utils.encoding import force_unicode
    2121
    22 re_formatchars = re.compile(r'(?<!\\)([aAbBcdDEfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
     22re_formatchars = re.compile(r'(?<!\\)([aAbBcdDeEfFgGhHiIjlLmMnNoOPrsStTUuwWyYzZ])')
    2323re_escaped = re.compile(r'\\(.)')
    2424
    2525class Formatter(object):
    class DateFormat(TimeFormat): 
    138138        "Day of the week, textual, 3 letters; e.g. 'Fri'"
    139139        return WEEKDAYS_ABBR[self.data.weekday()]
    140140
     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
    141152    def E(self):
    142153        "Alternative month names as required by some locales. Proprietary extension."
    143154        return MONTHS_ALT[self.data.month]
    class DateFormat(TimeFormat): 
    181192        "Month abbreviation in Associated Press style. Proprietary extension."
    182193        return MONTHS_AP[self.data.month]
    183194
     195    def o(self):
     196        "ISO 8601 year number matching the ISO week number (W)"
     197        return self.data.isocalendar()[0]
     198
    184199    def O(self):
    185200        "Difference to Greenwich time in hours; e.g. '+0200', '-0430'"
    186201        seconds = self.Z()
  • docs/ref/templates/builtins.txt

    diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
    index 4e5c124..33b1998 100644
    a b date 
    12451245
    12461246Formats a date according to the given format.
    12471247
    1248 Uses the same format as PHP's ``date()`` function (http://php.net/date)
    1249 with some custom extensions.
     1248Uses a similar format as PHP's ``date()`` function (http://php.net/date)
     1249with some differences.
    12501250
    12511251Available format strings:
    12521252
    c ISO 8601 format. (Note: unlike others ``2008-01-02T10:30:0 
    12681268d                 Day of the month, 2 digits with           ``'01'`` to ``'31'``
    12691269                  leading zeros.
    12701270D                 Day of the week, textual, 3 letters.      ``'Fri'``
     1271e                 Timezone name. Could be in any format,
     1272                  or might return an empty string,          ``''``, ``'GMT'``, ``'-500'``, ``'US/Eastern'``, etc.
     1273                  depending on the datetime.
    12711274E                 Month, locale specific alternative
    12721275                  representation usually used for long
    12731276                  date representation.                      ``'listopada'`` (for Polish locale, as opposed to ``'Listopad'``)
    M Month, textual, 3 letters. ``'Jan'`` 
    12921295n                 Month without leading zeros.              ``'1'`` to ``'12'``
    12931296N                 Month abbreviation in Associated Press    ``'Jan.'``, ``'Feb.'``, ``'March'``, ``'May'``
    12941297                  style. Proprietary extension.
     1298o                 ISO-8601 week-numbering year,             ``'1999'``
     1299                  corresponding to
     1300                  the ISO-8601 week number (W)
    12951301O                 Difference to Greenwich time in hours.    ``'+0200'``
    12961302P                 Time, in 12-hour hours, minutes and       ``'1 a.m.'``, ``'1:30 p.m.'``, ``'midnight'``, ``'noon'``, ``'12:30 p.m.'``
    12971303                  'a.m.'/'p.m.', with minutes left off
  • tests/regressiontests/templates/filters.py

    diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
    index 6b79349..9483578 100644
    a b def get_filter_tests(): 
    345345        'date02': (r'{{ d|date }}', {'d': datetime(2008, 1, 1)}, 'Jan. 1, 2008'),
    346346        #Ticket 9520: Make sure |date doesn't blow up on non-dates
    347347        '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)}, ''),
    348354
    349355         # Tests for #11687 and #16676
    350356         'add01': (r'{{ i|add:"5" }}', {'i': 2000}, '2005'),
Back to Top