Opened 3 years ago

Closed 7 months ago

Last modified 7 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

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 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 settings.py

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: 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 Changed 2 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 12 months ago by timo

  • Patch needs improvement set

Patch no longer applies cleanly.

comment:8 Changed 11 months ago by maxocub

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

comment:10 Changed 11 months ago by maxocub

  • Needs tests set

comment:11 Changed 11 months ago by maxocub

This PR needs to be reviewed please.

comment:12 Changed 11 months ago by maxocub

  • Needs tests unset
  • Patch needs improvement unset

comment:13 Changed 7 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 7 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 7 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