Opened 9 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 9 years ago.
Missmatching date for text/calendar

Download all attachments as: .zip

Change History (17)

comment:1 by Aymeric Augustin, 9 years ago

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 by Eric Druid, 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 Eric Druid, 9 years ago

Missmatching date for text/calendar

comment:3 by Tim Graham, 9 years ago

Component: Formscontrib.admin
Triage Stage: UnreviewedAccepted

I can reproduce this.

comment:4 by Sasha Gaevsky, 8 years ago

Version: 1.8master

I have reproduced this in the master branch as well.

comment:5 by Sasha Gaevsky, 8 years ago

Has patch: set

comment:6 by Tim Graham, 8 years ago

Severity: NormalRelease blocker
Version: master1.8

This is a regression in 1.8 caused by 25e06bca57c068d4b9e9b4221b16a667ccb0d38e.

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

Resolution: fixed
Status: newclosed

In 44930cc:

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

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

In 18bf062:

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

Backport of 44930cc4667268c20493d7e97387db2a97d61a26 from master

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

In 40601e5:

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

Backport of 44930cc4667268c20493d7e97387db2a97d61a26 from master

comment:10 by Tim Graham, 8 years ago

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

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

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 by Sasha Gaevsky, 8 years ago

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

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

In ea754289:

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

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

In 835fff4:

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

Backport of ea7542891a4e3638a695c58bd6f00658b7c85985 from master

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

In caeacd94:

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

Backport of ea7542891a4e3638a695c58bd6f00658b7c85985 from master

comment:16 by Tim Graham, 8 years ago

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