Ticket #6449: django-datetime-filter.3.patch
File django-datetime-filter.3.patch, 3.2 KB (added by , 17 years ago) |
---|
-
django/template/defaultfilters.py
617 617 # DATES # 618 618 ################### 619 619 620 def date (value, arg=None):621 """Formats a date according to the given format."""620 def datetime(value, arg=None): 621 """Formats a datetime according to the given format.""" 622 622 from django.utils.dateformat import format 623 623 if not value: 624 624 return u'' 625 625 if arg is None: 626 arg = settings.DATETIME_FORMAT 627 elif arg == 'x': 626 628 arg = settings.DATE_FORMAT 629 elif arg == 'X': 630 arg = settings.TIME_FORMAT 627 631 return format(value, arg) 632 datetime.is_safe = False 633 634 def 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) 628 639 date.is_safe = False 629 640 630 641 def time(value, arg=None): … … 800 811 register.filter(center) 801 812 register.filter(cut) 802 813 register.filter(date) 814 register.filter(datetime) 803 815 register.filter(default) 804 816 register.filter(default_if_none) 805 817 register.filter(dictsort) -
docs/templates.txt
957 957 leading zeros. 958 958 W ISO-8601 week number of year, with ``1``, ``53`` 959 959 weeks starting on Monday. 960 x Date formatted as `DATE_FORMAT`_. ``'Feb. 4, 2003'`` 961 X Time formatted as `TIME_FORMAT`_. ``'4 p.m.'`` 960 962 y Year, 2 digits. ``'99'`` 961 963 Y Year, 4 digits. ``'1999'`` 962 964 z Day of the year. ``0`` to ``365`` … … 979 981 980 982 This would display as "It is the 4th of September". 981 983 984 .. _DATE_FORMAT: ../settings/#date-format 985 .. _TIME_FORMAT: ../settings/#time-format 986 982 987 regroup 983 988 ~~~~~~~ 984 989 … … 1266 1271 1267 1272 Formats a date according to the given format (same as the `now`_ tag). 1268 1273 1274 Default: `DATE_FORMAT`_ 1275 1269 1276 For example:: 1270 1277 1271 1278 {{ value|date:"D d M Y" }} … … 1274 1281 ``datetime.datetime.now()``), the output will be the string 1275 1282 ``'Wed 09 Jan 2008'``. 1276 1283 1284 .. _DATE_FORMAT: ../settings/#date-format 1285 1286 datetime 1287 ~~~~~~~~ 1288 1289 Formats a datetime according to the given format (same as the `now`_ tag). 1290 1291 Default: `DATETIME_FORMAT`_ 1292 1293 For example:: 1294 1295 {{ value|datetime:"N j, Y, P" }} 1296 1297 If ``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 1277 1303 default 1278 1304 ~~~~~~~ 1279 1305 … … 1732 1758 to the time of day, not the date (for obvious reasons). If you need to 1733 1759 format a date, use the `date`_ filter. 1734 1760 1761 Default: `TIME_FORMAT`_ 1762 1735 1763 For example:: 1736 1764 1737 1765 {{ value|time:"H:i" }} … … 1739 1767 If ``value`` is equivalent to ``datetime.datetime.now()``, the output will be 1740 1768 the string ``"01:23"``. 1741 1769 1770 .. _TIME_FORMAT: ../settings/#time-format 1771 1742 1772 timesince 1743 1773 ~~~~~~~~~ 1744 1774