Opened 9 years ago
Closed 9 years ago
#24980 closed Bug (fixed)
Calendar selector for DateField defaults to wrong date when timezone is missmatching
Reported by: | Eric Druid | Owned by: | Sasha Gaevsky |
---|---|---|---|
Component: | contrib.admin | Version: | 1.8 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | yes |
Description
I have a server set to the time zone UTC and my browser set to CEST (UTC+2). The calendar helper will display the date before the selected one for date fields.
Steps to reproduce:
- Set TIME_ZONE = 'UTC' in settings.py
- Set timezone of local machine (where the browser is run from) to CEST
- Create a DateField that is printed in a form on an object
- Create an object
- View the objects interface, open the calendar js helper and notice that the selected date is the day before what is printed in the input box.
This is repeatable without saving the object, just select a different date and reopen the calendar and the date before the one clicked is used.
This is tested using python 2.7.6, django 1.8 using Chromium 43.0.2357.81
Attachments (1)
Change History (17)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
There is a warning for the mismatching timezone.
I'll attach an image displaying the problem.
In this case the Member object has the sql row:
id | first_name | last_name | date_of_birth | email | gender ----+------------+-----------+---------------+----------------------+-------- 1 | Eric | Druid | 1983-11-20 | eric.druid@gmail.com | m
The problem is the preselected 1983-11-19 rather than 1983-11-20.
It looks to me as if the javascript is converting the date (1983-11-20) in CEST as a timestamp (1983-11-20 00:00+2), then changing it to UTC (1983-11-19 22:00+0) and extracting the date (1983-11-19) and using that to mark the selected day.
by , 9 years ago
Attachment: | django_admin_calendar_missmatch.png added |
---|
Missmatching date for text/calendar
comment:3 by , 9 years ago
Component: | Forms → contrib.admin |
---|---|
Triage Stage: | Unreviewed → Accepted |
I can reproduce this.
comment:4 by , 9 years ago
Version: | 1.8 → master |
---|
I have reproduced this in the master branch as well.
comment:6 by , 9 years ago
Severity: | Normal → Release blocker |
---|---|
Version: | master → 1.8 |
This is a regression in 1.8 caused by 25e06bca57c068d4b9e9b4221b16a667ccb0d38e.
follow-up: 11 comment:10 by , 9 years ago
Has patch: | unset |
---|---|
Resolution: | fixed |
Status: | closed → new |
Looks like this broke some selenium tests: admin_widgets.tests.DateTimePickerSeleniumFirefoxTests.test_calendar_nonday_class
and test_calendar_selected_class
comment:11 by , 9 years ago
Replying to timgraham:
Looks like this broke some selenium tests:
admin_widgets.tests.DateTimePickerSeleniumFirefoxTests.test_calendar_nonday_class
andtest_calendar_selected_class
I'm looking into this.
comment:16 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Your date field must default to
datetime.date.today()
. This value is computed in the time zone you chose:TIME_ZONE = 'UTC'
. You're seeing the expected behavior.Django doesn't automatically set the time zone based on the browser's time zone for the reasons explained in the documentation: https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/#selecting-the-current-time-zone
For date time fields, the admin displays a warning when the browser's time zone doesn't match the server's time zone. Perhaps we should do this for date fields as well.