diff --git a/django/conf/__init__.py b/django/conf/__init__.py
a
|
b
|
|
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 hasattr(self, 'TIME_ZONE') and bool(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 |
diff --git a/django/conf/project_template/settings.py b/django/conf/project_template/settings.py
a
|
b
|
|
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 you can set it to None if you want Django don't |
| 27 | # touch the timezone at all so it stays equal to the server's timezone. |
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' |
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
a
|
b
|
|
119 | 119 | set_tz = False |
120 | 120 | settings_dict = self.settings_dict |
121 | 121 | if self.connection is None: |
122 | | set_tz = True |
| 122 | new_conn = True |
| 123 | set_tz = hasattr(settings, 'TIME_ZONE') and bool(settings.TIME_ZONE) |
123 | 124 | if settings_dict['NAME'] == '': |
124 | 125 | from django.core.exceptions import ImproperlyConfigured |
125 | 126 | raise ImproperlyConfigured("You need to specify NAME in your Django settings file.") |
… |
… |
|
136 | 137 | self.connection.set_isolation_level(1) # make transactions transparent to all cursors |
137 | 138 | connection_created.send(sender=self.__class__) |
138 | 139 | cursor = self.connection.cursor() |
139 | | if set_tz: |
140 | | cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) |
| 140 | if new_conn: |
| 141 | if set_tz: |
| 142 | cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) |
141 | 143 | if not hasattr(self, '_version'): |
142 | 144 | self.__class__._version = get_version(cursor) |
143 | 145 | if self._version[0:2] < (8, 0): |
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
a
|
b
|
|
110 | 110 | self.validation = BaseDatabaseValidation(self) |
111 | 111 | |
112 | 112 | def _cursor(self): |
| 113 | new_conn = False |
113 | 114 | set_tz = False |
114 | 115 | settings_dict = self.settings_dict |
115 | 116 | if self.connection is None: |
116 | | set_tz = True |
| 117 | new_conn = True |
| 118 | set_tz = hasattr(settings, 'TIME_ZONE') and bool(settings.TIME_ZONE) |
117 | 119 | if settings_dict['NAME'] == '': |
118 | 120 | from django.core.exceptions import ImproperlyConfigured |
119 | 121 | raise ImproperlyConfigured("You need to specify NAME in your Django settings file.") |
… |
… |
|
137 | 139 | connection_created.send(sender=self.__class__) |
138 | 140 | cursor = self.connection.cursor() |
139 | 141 | cursor.tzinfo_factory = None |
140 | | if set_tz: |
141 | | cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) |
| 142 | if new_conn: |
| 143 | if set_tz: |
| 144 | cursor.execute("SET TIME ZONE %s", [settings_dict['TIME_ZONE']]) |
142 | 145 | if not hasattr(self, '_version'): |
143 | 146 | self.__class__._version = get_version(cursor) |
144 | 147 | if self._version[0:2] < (8, 0): |
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
a
|
b
|
|
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.) |
| 1508 | A string representing the time zone for this installation or ``None``. `See |
| 1509 | available choices`_. (Note that list of available choices lists more than one |
| 1510 | on the same line; you'll want to use just one of the choices for a given time |
| 1511 | zone. For instance, one line says ``'Europe/London GB GB-Eire'``, but you should |
| 1512 | use the first bit of that -- ``'Europe/London'`` -- as your ``TIME_ZONE`` |
| 1513 | setting.) |
1513 | 1514 | |
1514 | 1515 | Note that this is the time zone to which Django will convert all dates/times -- |
1515 | 1516 | not necessarily the timezone of the server. For example, one server may serve |
1516 | 1517 | multiple Django-powered sites, each with a separate time-zone setting. |
1517 | 1518 | |
| 1519 | If the ``None`` value is used for this setting. Django will refrain from |
| 1520 | setting the timezone and the server system timezone will be used instead. |
| 1521 | |
1518 | 1522 | Normally, Django sets the ``os.environ['TZ']`` variable to the time zone you |
1519 | 1523 | 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. |
| 1524 | automatically operate in the correct time zone. However, in the following two |
| 1525 | scenarios: |
| 1526 | |
| 1527 | * If you set this setting to ``None``, as described above |
| 1528 | * If you're using the manual configuration option as described in |
| 1529 | :ref:`manually configuring settings <settings-without-django-settings-module>` |
| 1530 | |
| 1531 | Django will *not* touch the ``TZ`` environment variable, and it'll be up to you |
| 1532 | to ensure your processes are running in the correct environment. |
1525 | 1533 | |
1526 | 1534 | .. note:: |
1527 | 1535 | Django cannot reliably use alternate time zones in a Windows environment. |
1528 | 1536 | If you're running Django on Windows, this variable must be set to match the |
1529 | 1537 | system timezone. |
1530 | 1538 | |
| 1539 | .. versionadded:: 1.2 |
| 1540 | The possibility to set the value of this setting to ``None`` was added. |
| 1541 | |
1531 | 1542 | .. _See available choices: http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE |
1532 | 1543 | |
1533 | 1544 | .. setting:: URL_VALIDATOR_USER_AGENT |