Ticket #15263: now_tag.diff
File now_tag.diff, 2.9 KB (added by , 14 years ago) |
---|
-
django/template/defaulttags.py
381 381 382 382 def render(self, context): 383 383 from datetime import datetime 384 from django.utils.dateformat import DateFormat 385 df = DateFormat(datetime.now()) 386 return df.format(self.format_string) 384 from django.utils import formats 385 from django.utils import dateformat 386 now = datetime.now() 387 try: 388 return formats.date_format(now, self.format_string) 389 except AttributeError: 390 try: 391 return dateformat.format(now, self.format_string) 392 except AttributeError: 393 return '' 387 394 388 395 class SpacelessNode(Node): 389 396 def __init__(self, nodelist): -
docs/ref/templates/builtins.txt
680 680 681 681 Display the current date and/or time, according to the given string. 682 682 683 Given format can be one of the predefined ones``DATE_FORMAT``,684 ``DATETIME_FORMAT``, ``SHORT_DATE_FORMAT`` or ``SHORT_DATETIME_FORMAT`` ,685 or a custom format, same asthe :tfilter:`date` filter. Note that predefined683 The format string can be one of the predefined ones - ``DATE_FORMAT``, 684 ``DATETIME_FORMAT``, ``SHORT_DATE_FORMAT`` or ``SHORT_DATETIME_FORMAT`` - 685 or a custom format, as with the :tfilter:`date` filter. Note that predefined 686 686 formats may vary depending on the current locale. 687 687 688 688 Example:: -
tests/regressiontests/templates/tests.py
18 18 from django.template import loader 19 19 from django.template.loaders import app_directories, filesystem, cached 20 20 from django.utils import unittest 21 from django.utils.formats import date_format 21 22 from django.utils.translation import activate, deactivate, ugettext as _ 22 23 from django.utils.safestring import mark_safe 23 24 from django.utils.tzinfo import LocalTimezone … … 1379 1380 'now02': ('{% now "j "n" Y"%}', {}, template.TemplateSyntaxError), 1380 1381 # 'now03': ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + '"' + str(datetime.now().month) + '"' + str(datetime.now().year)), 1381 1382 # 'now04': ('{% now "j \nn\n Y"%}', {}, str(datetime.now().day) + '\n' + str(datetime.now().month) + '\n' + str(datetime.now().year)) 1383 # Check parsing of locale strings 1384 'now05': ('{% now "DATE_FORMAT" %}', {}, date_format(datetime.now())), 1382 1385 1383 1386 ### URL TAG ######################################################## 1384 1387 # Successes