Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17274 -- Accepted TIME_ZONE = None when USE_TZ = True. Thanks …

…pressureman for the report.

This problem only occured when pytz is installed. It's still strongly recommended to define the correct time zone in TIME_ZONE in order to use pytz' implementation and not the approximation based on system time.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@17134 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 43c5d35315299330aaca1e2aab6fd2548eff7fcb 1 parent c5a899b
Aymeric Augustin authored November 21, 2011
6  django/utils/timezone.py
@@ -102,8 +102,10 @@ def get_default_timezone():
102 102
     """
103 103
     global _localtime
104 104
     if _localtime is None:
105  
-        tz = settings.TIME_ZONE
106  
-        _localtime = pytz.timezone(tz) if pytz else LocalTimezone()
  105
+        if isinstance(settings.TIME_ZONE, basestring) and pytz is not None:
  106
+            _localtime = pytz.timezone(settings.TIME_ZONE)
  107
+        else:
  108
+            _localtime = LocalTimezone()
107 109
     return _localtime
108 110
 
109 111
 # This function exists for consistency with get_current_timezone_name
11  tests/modeltests/timezones/tests.py
@@ -774,6 +774,17 @@ def test_date_and_time_template_filters_honor_localtime(self):
774 774
         with timezone.override(ICT):
775 775
             self.assertEqual(tpl.render(ctx), "2011-09-01 at 20:20:20")
776 776
 
  777
+    def test_localtime_with_time_zone_setting_set_to_none(self):
  778
+        # Regression for #17274
  779
+        tpl = Template("{% load tz %}{{ dt }}")
  780
+        ctx = Context({'dt': datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT)})
  781
+
  782
+        timezone._localtime = None
  783
+        with self.settings(TIME_ZONE=None):
  784
+            # the actual value depends on the system time zone of the host
  785
+            self.assertTrue(tpl.render(ctx).startswith("2011"))
  786
+        timezone._localtime = None
  787
+
777 788
 TemplateTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(TemplateTests)
778 789
 
779 790
 #@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)

0 notes on commit 43c5d35

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