Opened 8 years ago

Closed 8 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:

  1. Set TIME_ZONE = 'UTC' in settings.py
  2. Set timezone of local machine (where the browser is run from) to CEST
  3. Create a DateField that is printed in a form on an object
  4. Create an object
  5. 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)

django_admin_calendar_missmatch.png (25.9 KB) - added by Eric Druid 8 years ago.
Missmatching date for text/calendar

Download all attachments as: .zip

Change History (17)

comment:1 Changed 8 years ago by Aymeric Augustin

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.

comment:2 Changed 8 years ago by Eric Druid

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.

Changed 8 years ago by Eric Druid

Missmatching date for text/calendar

comment:3 Changed 8 years ago by Tim Graham

Component: Formscontrib.admin
Triage Stage: UnreviewedAccepted

I can reproduce this.

comment:4 Changed 8 years ago by Sasha Gaevsky

Version: 1.8master

I have reproduced this in the master branch as well.

comment:5 Changed 8 years ago by Sasha Gaevsky

Has patch: set

comment:6 Changed 8 years ago by Tim Graham

Severity: NormalRelease blocker
Version: master1.8

This is a regression in 1.8 caused by 25e06bca57c068d4b9e9b4221b16a667ccb0d38e.

comment:7 Changed 8 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 44930cc:

Fixed #24980 -- Fixed day determination in admin calendar widget.

comment:8 Changed 8 years ago by Tim Graham <timograham@…>

In 18bf062:

[1.9.x] Fixed #24980 -- Fixed day determination in admin calendar widget.

Backport of 44930cc4667268c20493d7e97387db2a97d61a26 from master

comment:9 Changed 8 years ago by Tim Graham <timograham@…>

In 40601e5:

[1.8.x] Fixed #24980 -- Fixed day determination in admin calendar widget.

Backport of 44930cc4667268c20493d7e97387db2a97d61a26 from master

comment:10 Changed 8 years ago by Tim Graham

Has patch: unset
Resolution: fixed
Status: closednew

Looks like this broke some selenium tests: admin_widgets.tests.DateTimePickerSeleniumFirefoxTests.test_calendar_nonday_class and test_calendar_selected_class

comment:11 in reply to:  10 Changed 8 years ago by Sasha Gaevsky

Replying to timgraham:

Looks like this broke some selenium tests: admin_widgets.tests.DateTimePickerSeleniumFirefoxTests.test_calendar_nonday_class and test_calendar_selected_class

I'm looking into this.

comment:12 Changed 8 years ago by Sasha Gaevsky

Has patch: set
Owner: changed from nobody to Sasha Gaevsky
Status: newassigned

comment:13 Changed 8 years ago by Tim Graham <timograham@…>

In ea754289:

Refs #24980 -- Fixed incorrect timezone handling in admin calendar widget.

comment:14 Changed 8 years ago by Tim Graham <timograham@…>

In 835fff4:

[1.9.x] Refs #24980 -- Fixed incorrect timezone handling in admin calendar widget.

Backport of ea7542891a4e3638a695c58bd6f00658b7c85985 from master

comment:15 Changed 8 years ago by Tim Graham <timograham@…>

In caeacd94:

[1.8.x] Refs #24980 -- Fixed incorrect timezone handling in admin calendar widget.

Backport of ea7542891a4e3638a695c58bd6f00658b7c85985 from master

comment:16 Changed 8 years ago by Tim Graham

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top