Commit a7b09e7
committed
Obey the connection's TIME_ZONE setting when USE_TZ enabled
Given that SQL server has no built-in support for timezones, we have set
DatabaseFeatures.supports_timezones = False. However, we incorrectly
assumed that every datetime stored in the database is in UTC, and have
hardcoded timezone.utc.
Django allows developers to set the TIME_ZONE option in a database's
connection settings to specify the timezone in which the datetimes are
stored, and this library should obey that setting.
See:
https://docs.djangoproject.com/en/1.11/ref/settings/#time-zone
To obey the TIME_ZONE setting, we replace timezone.utc with
self.connection.timezone, which is a cached_property we inherit from
BaseDatabaseWrapper. The calculation of the property includes various
checks, and will default to timezone.utc if no TIME_ZONE setting is
provided for a database connection - meaning this change will be
backward compatible.
See:
https://github.com/django/django/blob/1.11.4/django/db/backends/base/base.py#L121-L1281 parent 4df37f3 commit a7b09e7
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| |||
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
483 | | - | |
| 483 | + | |
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
| |||
0 commit comments