Ticket #6449: django-datetime-filter.3.patch

File django-datetime-filter.3.patch, 3.2 KB (added by Harm Geerts, 16 years ago)

patch including documentation, reverted my change to the timefilter because the docs mention date parameters are not allowed

  • django/template/defaultfilters.py

     
    617617# DATES           #
    618618###################
    619619
    620 def date(value, arg=None):
    621     """Formats a date according to the given format."""
     620def datetime(value, arg=None):
     621    """Formats a datetime according to the given format."""
    622622    from django.utils.dateformat import format
    623623    if not value:
    624624        return u''
    625625    if arg is None:
     626        arg = settings.DATETIME_FORMAT
     627    elif arg == 'x':
    626628        arg = settings.DATE_FORMAT
     629    elif arg == 'X':
     630        arg = settings.TIME_FORMAT
    627631    return format(value, arg)
     632datetime.is_safe = False
     633
     634def date(value, arg=None):
     635    """Formats a date according to the given format."""
     636    if arg is None:
     637        arg = settings.DATE_FORMAT
     638    return datetime(value, arg)
    628639date.is_safe = False
    629640
    630641def time(value, arg=None):
     
    800811register.filter(center)
    801812register.filter(cut)
    802813register.filter(date)
     814register.filter(datetime)
    803815register.filter(default)
    804816register.filter(default_if_none)
    805817register.filter(dictsort)
  • docs/templates.txt

     
    957957                      leading zeros.
    958958    W                 ISO-8601 week number of year, with        ``1``, ``53``
    959959                      weeks starting on Monday.
     960    x                 Date formatted as `DATE_FORMAT`_.         ``'Feb. 4, 2003'``
     961    X                 Time formatted as `TIME_FORMAT`_.         ``'4 p.m.'``
    960962    y                 Year, 2 digits.                           ``'99'``
    961963    Y                 Year, 4 digits.                           ``'1999'``
    962964    z                 Day of the year.                          ``0`` to ``365``
     
    979981
    980982This would display as "It is the 4th of September".
    981983
     984.. _DATE_FORMAT: ../settings/#date-format
     985.. _TIME_FORMAT: ../settings/#time-format
     986
    982987regroup
    983988~~~~~~~
    984989
     
    12661271
    12671272Formats a date according to the given format (same as the `now`_ tag).
    12681273
     1274Default: `DATE_FORMAT`_
     1275
    12691276For example::
    12701277
    12711278    {{ value|date:"D d M Y" }}
     
    12741281``datetime.datetime.now()``), the output will be the string
    12751282``'Wed 09 Jan 2008'``.
    12761283
     1284.. _DATE_FORMAT: ../settings/#date-format
     1285
     1286datetime
     1287~~~~~~~~
     1288
     1289Formats a datetime according to the given format (same as the `now`_ tag).
     1290
     1291Default: `DATETIME_FORMAT`_
     1292
     1293For example::
     1294
     1295    {{ value|datetime:"N j, Y, P" }}
     1296
     1297If ``value`` is a ``datetime`` object (e.g., the result of
     1298``datetime.datetime.now()``), the output will be the string
     1299``'Feb. 4, 2003, 4 p.m.'``.
     1300
     1301.. _DATETIME_FORMAT: ../settings/#datetime-format
     1302
    12771303default
    12781304~~~~~~~
    12791305
     
    17321758to the time of day, not the date (for obvious reasons). If you need to
    17331759format a date, use the `date`_ filter.
    17341760
     1761Default: `TIME_FORMAT`_
     1762
    17351763For example::
    17361764
    17371765    {{ value|time:"H:i" }}
     
    17391767If ``value`` is equivalent to ``datetime.datetime.now()``, the output will be
    17401768the string ``"01:23"``.
    17411769
     1770.. _TIME_FORMAT: ../settings/#time-format
     1771
    17421772timesince
    17431773~~~~~~~~~
    17441774
Back to Top