Opened 3 years ago

Closed 16 months ago

Last modified 16 months ago

#18767 closed Bug (fixed)

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

Reported by: void Owned by: maxocub
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: apollo13 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 3 years ago by void

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by anonymous

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

comment:3 Changed 3 years ago by void

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

comment:4 Changed 3 years ago by apollo13

  • Cc apollo13 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 3 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 3 years ago by tswicegood

  • Triage Stage changed from Unreviewed to Accepted

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 21 months ago by timo

  • Patch needs improvement set

Patch no longer applies cleanly.

comment:8 Changed 20 months ago by maxocub

  • Owner changed from nobody to maxocub
  • Status changed from new to assigned

comment:10 Changed 20 months ago by maxocub

  • Needs tests set

comment:11 Changed 20 months ago by maxocub

This PR needs to be reviewed please.

comment:12 Changed 20 months ago by maxocub

  • Needs tests unset
  • Patch needs improvement unset

comment:13 Changed 16 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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 16 months ago by claudep

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 16 months ago by maxocub

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