Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17343 -- Changed the {% now %} tag to use the current time zon…

…e when time zone support is enabled. Thanks oinopion for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17169 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 33bb3cd47cb287daa1246b705eff0f55bf72d284 1 parent e42360b
Aymeric Augustin authored December 04, 2011
4  django/template/defaulttags.py
@@ -15,6 +15,7 @@
15 15
 from django.template.defaultfilters import date
16 16
 from django.utils.encoding import smart_str, smart_unicode
17 17
 from django.utils.safestring import mark_safe
  18
+from django.utils import timezone
18 19
 
19 20
 register = Library()
20 21
 
@@ -343,7 +344,8 @@ def __init__(self, format_string):
343 344
         self.format_string = format_string
344 345
 
345 346
     def render(self, context):
346  
-        return date(datetime.now(), self.format_string)
  347
+        tzinfo = timezone.get_current_timezone() if settings.USE_TZ else None
  348
+        return date(datetime.now(tz=tzinfo), self.format_string)
347 349
 
348 350
 class SpacelessNode(Node):
349 351
     def __init__(self, nodelist):
7  tests/modeltests/timezones/tests.py
@@ -790,6 +790,13 @@ def test_localtime_with_time_zone_setting_set_to_none(self):
790 790
             self.assertTrue(tpl.render(ctx).startswith("2011"))
791 791
         timezone._localtime = None
792 792
 
  793
+    def test_now_template_tag_uses_current_time_zone(self):
  794
+        # Regression for #17343
  795
+        tpl = Template("{% now \"O\" %}")
  796
+        self.assertEqual(tpl.render(Context({})), "+0300")
  797
+        with timezone.override(ICT):
  798
+            self.assertEqual(tpl.render(Context({})), "+0700")
  799
+
793 800
 TemplateTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(TemplateTests)
794 801
 
795 802
 #@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)

0 notes on commit 33bb3cd

Please sign in to comment.
Something went wrong with that request. Please try again.