Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #1480 -- Added the ability to use the system timezone. …

…Thanks to Ramiro Morales for the patch.

Backport of r12602 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12603 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b6bd766d88aedfb924180091bebbe990b7b64564 1 parent 0c2d3ff
Russell Keith-Magee authored February 26, 2010
2  django/conf/__init__.py
@@ -102,7 +102,7 @@ def __init__(self, settings_module):
102 102
                 new_installed_apps.append(app)
103 103
         self.INSTALLED_APPS = new_installed_apps
104 104
 
105  
-        if hasattr(time, 'tzset'):
  105
+        if hasattr(time, 'tzset') and getattr(self, 'TIME_ZONE'):
106 106
             # Move the time zone info into os.environ. See ticket #2315 for why
107 107
             # we don't do this unconditionally (breaks Windows).
108 108
             os.environ['TZ'] = self.TIME_ZONE
2  django/conf/project_template/settings.py
@@ -19,6 +19,8 @@
19 19
 # Local time zone for this installation. Choices can be found here:
20 20
 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
21 21
 # although not all choices may be available on all operating systems.
  22
+# On Unix systems, a value of None will cause Django to use the same
  23
+# timezone as the operating system.
22 24
 # If running in a Windows environment this must be set to the same as your
23 25
 # system time zone.
24 26
 TIME_ZONE = 'America/Chicago'
2  django/db/backends/postgresql/base.py
@@ -100,7 +100,7 @@ def _cursor(self):
100 100
         set_tz = False
101 101
         settings_dict = self.settings_dict
102 102
         if self.connection is None:
103  
-            set_tz = True
  103
+            set_tz = settings_dict.get('TIME_ZONE')
104 104
             if settings_dict['DATABASE_NAME'] == '':
105 105
                 from django.core.exceptions import ImproperlyConfigured
106 106
                 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
2  django/db/backends/postgresql_psycopg2/base.py
@@ -77,7 +77,7 @@ def _cursor(self):
77 77
         set_tz = False
78 78
         settings_dict = self.settings_dict
79 79
         if self.connection is None:
80  
-            set_tz = True
  80
+            set_tz = settings_dict.get('TIME_ZONE')
81 81
             if settings_dict['DATABASE_NAME'] == '':
82 82
                 from django.core.exceptions import ImproperlyConfigured
83 83
                 raise ImproperlyConfigured("You need to specify DATABASE_NAME in your Django settings file.")
54  docs/ref/settings.txt
@@ -1145,28 +1145,42 @@ TIME_ZONE
1145 1145
 
1146 1146
 Default: ``'America/Chicago'``
1147 1147
 
1148  
-A string representing the time zone for this installation. `See available choices`_.
1149  
-(Note that list of available choices lists more than one on the same line;
1150  
-you'll want to use just one of the choices for a given time zone. For instance,
1151  
-one line says ``'Europe/London GB GB-Eire'``, but you should use the first bit
1152  
-of that -- ``'Europe/London'`` -- as your ``TIME_ZONE`` setting.)
1153  
-
1154  
-Note that this is the time zone to which Django will convert all dates/times --
1155  
-not necessarily the timezone of the server. For example, one server may serve
1156  
-multiple Django-powered sites, each with a separate time-zone setting.
1157  
-
1158  
-Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you
1159  
-specify in the ``TIME_ZONE`` setting. Thus, all your views and models will
1160  
-automatically operate in the correct time zone. However, if you're manually
1161  
-:ref:`manually configuring settings
1162  
-<settings-without-django-settings-module>`, Django will *not* touch the ``TZ``
1163  
-environment variable, and it'll be up to you to ensure your processes are
1164  
-running in the correct environment.
  1148
+.. versionchanged:: 1.2
  1149
+   ``None`` was added as an allowed value.
  1150
+
  1151
+A string representing the time zone for this installation, or
  1152
+``None``. `See available choices`_. (Note that list of available
  1153
+choices lists more than one on the same line; you'll want to use just
  1154
+one of the choices for a given time zone. For instance, one line says
  1155
+``'Europe/London GB GB-Eire'``, but you should use the first bit of
  1156
+that -- ``'Europe/London'`` -- as your ``TIME_ZONE`` setting.)
  1157
+
  1158
+Note that this is the time zone to which Django will convert all
  1159
+dates/times -- not necessarily the timezone of the server. For
  1160
+example, one server may serve multiple Django-powered sites, each with
  1161
+a separate time-zone setting.
  1162
+
  1163
+Normally, Django sets the ``os.environ['TZ']`` variable to the time
  1164
+zone you specify in the ``TIME_ZONE`` setting. Thus, all your views
  1165
+and models will automatically operate in the correct time zone.
  1166
+However, Django won't set the ``TZ`` environment variable under the
  1167
+following conditions:
  1168
+
  1169
+ * If you're using the manual configuration option as described in
  1170
+   :ref:`manually configuring settings
  1171
+   <settings-without-django-settings-module>`, or
  1172
+
  1173
+ * If you specify ``TIME_ZONE = None``. This will cause Django to fall
  1174
+   back to using the system timezone.
  1175
+
  1176
+If Django doesn't set the ``TZ`` environment variable, it's up to you
  1177
+to ensure your processes are running in the correct environment.
1165 1178
 
1166 1179
 .. note::
1167  
-    Django cannot reliably use alternate time zones in a Windows environment.
1168  
-    If you're running Django on Windows, this variable must be set to match the
1169  
-    system timezone.
  1180
+    Django cannot reliably use alternate time zones in a Windows
  1181
+    environment. If you're running Django on Windows, this variable
  1182
+    must be set to match the system timezone.
  1183
+
1170 1184
 
1171 1185
 .. _See available choices: http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
1172 1186
 
2  tests/regressiontests/app_loading/tests.py
@@ -19,7 +19,7 @@
19 19
 >>> sys.path = old_sys_path
20 20
 
21 21
 # Undo a side-effect of installing a new settings object.
22  
->>> if hasattr(time, "tzset"):
  22
+>>> if hasattr(time, "tzset") and old_tz:
23 23
 ...     os.environ["TZ"] = old_tz
24 24
 ...     time.tzset()
25 25
 

0 notes on commit b6bd766

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