Opened 6 years ago

Closed 4 years ago

Last modified 4 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: master
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


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 Changed 6 years ago by Alexey Boriskin

Has patch: set

comment:2 Changed 6 years ago by anonymous

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

comment:3 Changed 6 years ago by Alexey Boriskin

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

comment:4 Changed 5 years ago by Florian Apolloner

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 Changed 5 years ago by anonymous

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

comment:6 Changed 5 years ago by Travis Swicegood

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 Changed 4 years ago by Tim Graham

Patch needs improvement: set

Patch no longer applies cleanly.

comment:8 Changed 4 years ago by Maxime Turcotte

Owner: changed from nobody to Maxime Turcotte
Status: newassigned

comment:10 Changed 4 years ago by Maxime Turcotte

Needs tests: set

comment:11 Changed 4 years ago by Maxime Turcotte

This PR needs to be reviewed please.

comment:12 Changed 4 years ago by Maxime Turcotte

Needs tests: unset
Patch needs improvement: unset

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

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 Changed 4 years ago by Claude Paroz

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 Changed 4 years ago by Maxime Turcotte

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