Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1480 -- Added the ability to use the system timezone. Thanks t…

…o Ramiro Morales for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12602 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 46cc7021a8ab60190d81e9d7e039cd84efbafb23 1 parent 0ff624a
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
@@ -23,6 +23,8 @@
23 23
 # Local time zone for this installation. Choices can be found here:
24 24
 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
25 25
 # although not all choices may be available on all operating systems.
  26
+# On Unix systems, a value of None will cause Django to use the same
  27
+# timezone as the operating system.
26 28
 # If running in a Windows environment this must be set to the same as your
27 29
 # system time zone.
28 30
 TIME_ZONE = 'America/Chicago'
2  django/db/backends/postgresql/base.py
@@ -119,7 +119,7 @@ def _cursor(self):
119 119
         set_tz = False
120 120
         settings_dict = self.settings_dict
121 121
         if self.connection is None:
122  
-            set_tz = True
  122
+            set_tz = settings_dict.get('TIME_ZONE')
123 123
             if settings_dict['NAME'] == '':
124 124
                 from django.core.exceptions import ImproperlyConfigured
125 125
                 raise ImproperlyConfigured("You need to specify NAME in your Django settings file.")
2  django/db/backends/postgresql_psycopg2/base.py
@@ -113,7 +113,7 @@ def _cursor(self):
113 113
         set_tz = False
114 114
         settings_dict = self.settings_dict
115 115
         if self.connection is None:
116  
-            set_tz = True
  116
+            set_tz = settings_dict.get('TIME_ZONE')
117 117
             if settings_dict['NAME'] == '':
118 118
                 from django.core.exceptions import ImproperlyConfigured
119 119
                 raise ImproperlyConfigured("You need to specify NAME in your Django settings file.")
54  docs/ref/settings.txt
@@ -1505,28 +1505,42 @@ TIME_ZONE
1505 1505
 
1506 1506
 Default: ``'America/Chicago'``
1507 1507
 
1508  
-A string representing the time zone for this installation. `See available choices`_.
1509  
-(Note that list of available choices lists more than one on the same line;
1510  
-you'll want to use just one of the choices for a given time zone. For instance,
1511  
-one line says ``'Europe/London GB GB-Eire'``, but you should use the first bit
1512  
-of that -- ``'Europe/London'`` -- as your ``TIME_ZONE`` setting.)
1513  
-
1514  
-Note that this is the time zone to which Django will convert all dates/times --
1515  
-not necessarily the timezone of the server. For example, one server may serve
1516  
-multiple Django-powered sites, each with a separate time-zone setting.
1517  
-
1518  
-Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you
1519  
-specify in the ``TIME_ZONE`` setting. Thus, all your views and models will
1520  
-automatically operate in the correct time zone. However, if you're manually
1521  
-:ref:`manually configuring settings
1522  
-<settings-without-django-settings-module>`, Django will *not* touch the ``TZ``
1523  
-environment variable, and it'll be up to you to ensure your processes are
1524  
-running in the correct environment.
  1508
+.. versionchanged:: 1.2
  1509
+   ``None`` was added as an allowed value.
  1510
+
  1511
+A string representing the time zone for this installation, or
  1512
+``None``. `See available choices`_. (Note that list of available
  1513
+choices lists more than one on the same line; you'll want to use just
  1514
+one of the choices for a given time zone. For instance, one line says
  1515
+``'Europe/London GB GB-Eire'``, but you should use the first bit of
  1516
+that -- ``'Europe/London'`` -- as your ``TIME_ZONE`` setting.)
  1517
+
  1518
+Note that this is the time zone to which Django will convert all
  1519
+dates/times -- not necessarily the timezone of the server. For
  1520
+example, one server may serve multiple Django-powered sites, each with
  1521
+a separate time-zone setting.
  1522
+
  1523
+Normally, Django sets the ``os.environ['TZ']`` variable to the time
  1524
+zone you specify in the ``TIME_ZONE`` setting. Thus, all your views
  1525
+and models will automatically operate in the correct time zone.
  1526
+However, Django won't set the ``TZ`` environment variable under the
  1527
+following conditions:
  1528
+
  1529
+ * If you're using the manual configuration option as described in
  1530
+   :ref:`manually configuring settings
  1531
+   <settings-without-django-settings-module>`, or
  1532
+
  1533
+ * If you specify ``TIME_ZONE = None``. This will cause Django to fall
  1534
+   back to using the system timezone.
  1535
+
  1536
+If Django doesn't set the ``TZ`` environment variable, it's up to you
  1537
+to ensure your processes are running in the correct environment.
1525 1538
 
1526 1539
 .. note::
1527  
-    Django cannot reliably use alternate time zones in a Windows environment.
1528  
-    If you're running Django on Windows, this variable must be set to match the
1529  
-    system timezone.
  1540
+    Django cannot reliably use alternate time zones in a Windows
  1541
+    environment. If you're running Django on Windows, this variable
  1542
+    must be set to match the system timezone.
  1543
+
1530 1544
 
1531 1545
 .. _See available choices: http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
1532 1546
 
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 46cc702

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