Opened 12 years ago

Closed 10 years ago

Last modified 10 years ago

#18767 closed Bug (fixed)

Admin's calendar for datetime fields doesn't show right values with russian and some other locales

Reported by: Alexey Boriskin Owned by: Maxime Turcotte
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Florian Apolloner Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The problem is within following lines:

        if (inp.value) {
            var date_parts = inp.value.split('-');
            var year = date_parts[0];
            var month = parseFloat(date_parts[1]);
            if (year.match(/\d\d\d\d/) && month >= 1 && month <= 12) {
                DateTimeShortcuts.calendars[num].drawDate(month, year);
            }
        }

These lines assume that date format is YYYY-mm-dd, which is not true for many locales.

Change History (15)

comment:1 by Alexey Boriskin, 12 years ago

Has patch: set

comment:2 by anonymous, 12 years ago

I do not have that problem, describe the regional settings that are installed on your system.

comment:3 by Alexey Boriskin, 12 years ago

I believe it's enough to have LANGUAGE_CODE = 'ru-ru' in the settings.py

comment:4 by Florian Apolloner, 12 years ago

Cc: Florian Apolloner added

Please describe what you see (probably with a screenshot) and what's wrong there, putting 'ru-ru' as LANGUAGE_CODE doesn't seem to break anything for me…

comment:5 by anonymous, 12 years ago

Ok, maybe I was not so clear in the description of this ticket.
Let's make django model with DateTimeField and register it with django admin. You'll see something like this: http://dl.dropbox.com/u/302516/Screenshots/usualform.png. Date is in format 01.02.1986, which means it's 1st of February of 1986.
Then click on the calendar icon and we'll see calendar popup: http://dl.dropbox.com/u/302516/Screenshots/r.png. But the popup is rendered for August 2012 (as you may see in the title: Август 2012). If I'd switch my LANGUAGE_CODE to 'en-us', I see that calendar popup renders correct month: http://dl.dropbox.com/u/302516/Screenshots/correct.png.

comment:6 by Travis Swicegood, 12 years ago

Triage Stage: UnreviewedAccepted

I was able to reproduce this.

The issue is that the calendar should display for the month/year of the date that is set. Steps to reproduce:

  • Set calendar date to February 1, 2000 (Russian date is 01.02.2000)
  • Click the calendar icon
  • Excepted behavior: Calendar is set to February 2000
  • Actual behavior: Calendar is set to whatever it last was

comment:7 by Tim Graham, 11 years ago

Patch needs improvement: set

Patch no longer applies cleanly.

comment:8 by Maxime Turcotte, 11 years ago

Owner: changed from nobody to Maxime Turcotte
Status: newassigned

comment:10 by Maxime Turcotte, 11 years ago

Needs tests: set

comment:11 by Maxime Turcotte, 11 years ago

This PR needs to be reviewed please.

comment:12 by Maxime Turcotte, 11 years ago

Needs tests: unset
Patch needs improvement: unset

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

Resolution: fixed
Status: assignedclosed

In 25e06bca57c068d4b9e9b4221b16a667ccb0d38e:

Fixed #18767 -- Fixed admin calendar for other locales than English.

Refactored openCalendar function from DateTimeShortcuts.js. Now, when
entered manually in the input field, the date will show up correctly on
the calendar for locales that don't use "-" for separator.

Thanks charettes for revivew and Alexey Boriskin for some of the patch.

comment:14 by Claude Paroz, 10 years ago

I just noticed that the test might add ~30 seconds to the test suite. Is testing every language really mandatory in this case?

comment:15 by Maxime Turcotte, 10 years ago

I guess we could only test the 4 or 5 different types of date format.

Note: See TracTickets for help on using tickets.
Back to Top