Opened 19 years ago
Closed 18 years ago
#1149 closed defect (duplicate)
'now' outputs in UTC and UTC-offset wrong on Windows
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Core (Other) | Version: | |
Severity: | normal | Keywords: | now utc time date zone Windows XP |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When the 'now' tag is used in a template, the output is always in UTC and the 'TIME_ZONE' setting appears to be used incorrectly. This behavior has been observed on Windows XP Pro (I have not tried it on other platforms).
Example #1: settings.py: TIME_ZONE = 'America/Chicago' template: {% now "O Y-M-d H:i" %} Windows Control Panel -> Date/Time -> Time Zone: US Central Result: +0000 2005-Dec-31 16:40
This result is exactly 6 hours ahead of the current local time.
Example #2 (same as above but with the following change: settings.py: TIME_ZONE = '' Result: +1800 2005-Dec-31 10:41
This result is the correct local time but the UTC offset of +1800 is wrong.
Change History (7)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
It seems that both the now tag and date filter are broken in templates, which is odd because django.utils.dateformat.format doesn't return bogus information (aside from it being '+1600' rather than '-800', and the expansion of 'PST'):
>>> from django.utils.dateformat import format >>> from django.models.news import entries >>> pub_date = entries.get_list()[0].pub_date >>> pub_date datetime.datetime(2006, 1, 7, 21, 53) >>> format(pub_date, "h:i A T (O)") '09:53 PM Pacific Standard Time (+1600)'
But
{{ entry.pub_date|date:"h:i A T (O)" }}
Outputs '09:53 PM Ame (+0000)'.
I assume that 'Ame' comes from "America/Los_Angeles", my TIME_ZONE.
comment:3 by , 19 years ago
Changing 'America/Los_Angeles' to 'PST8PDT' fixes this ('O' outputs +1600, 'T' outputs 'PST'), but only after the development server was killed and started again--for some reason the autoreload after saving settings.py doesn't update TIME_ZONE.
(Probably the cause of the strange behavior of format, above, as I was changing the TIME_ZONE settings but not manually restarting the server.)
comment:4 by , 19 years ago
Yes, the development server does not read the TIME_ZONE settings on reload. I already filed this behavior as ticket #1120 some time ago.
comment:5 by , 18 years ago
Component: | Template system → Core framework |
---|
Putting TIME_ZONE = in settings.py does not work for Windows 2000 because when trying to run the server, I get next error:
.python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\python25\lib\site-packages\django\core\management.py", line 1404, in execute_manager execute_from_command_line(action_mapping, argv)
File "C:\python25\lib\site-packages\django\core\management.py", line 1307, in
execute_from_command_line
from django.utils import translation
File "C:\python25\lib\site-packages\django\utils\translation\init.py", lin
e 3, in <module>
if settings.USE_I18N:
File "C:\python25\lib\site-packages\django\conf\init.py", line 27, in ge
tattr
self._import_settings()
File "C:\python25\lib\site-packages\django\conf\init.py", line 54, in _imp
ort_settings
self._target = Settings(settings_module)
File "C:\python25\lib\site-packages\django\conf\init.py", line 109, in i
nit
os.environTZ = self.TIME_ZONE
File "C:\python25/lib\os.py", line 426, in setitem
putenv(key, item)
OSError: [Errno 2] No such file or directory
comment:6 by , 18 years ago
Sorry:
Putting TIME_ZONE = "" in settings.py does not work for Windows 2000 because when trying ......
comment:7 by , 18 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I think this is the same issue as #2315: as soon as os.environ['TZ'] = self.TIME_ZONE
is set, Windows starts having a bit of a mental time disassociative disorder.
Seems to me like a dublicate of ticket #1119, isn't it?