1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

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.
This commit is contained in:
Maxime Turcotte
2014-04-15 15:01:55 -04:00
committed by Tim Graham
parent 2a9f44dfbe
commit 25e06bca57
3 changed files with 77 additions and 5 deletions

View File

@@ -290,11 +290,12 @@ var DateTimeShortcuts = {
// Determine if the current value in the input has a valid date.
// If so, draw the calendar with that date's year and month.
if (inp.value) {
var date_parts = inp.value.split('-');
var year = date_parts[0];
var month = parseFloat(date_parts[1]);
var selected = new Date(inp.value);
if (year.match(/\d\d\d\d/) && month >= 1 && month <= 12) {
var format = get_format('DATE_INPUT_FORMATS')[0];
var selected = inp.value.strptime(format);
var year = selected.getFullYear();
var month = selected.getMonth() + 1;
var re = /\d{4}/
if (re.test(year.toString()) && month >= 1 && month <= 12) {
DateTimeShortcuts.calendars[num].drawDate(month, year, selected);
}
}

View File

@@ -204,6 +204,30 @@ String.prototype.pad_left = function(pad_length, pad_string) {
return new_string;
}
String.prototype.strptime = function(format) {
var split_format = format.split(/[.\-/]/);
var date = this.split(/[.\-/]/);
var i = 0;
while (i < split_format.length) {
switch (split_format[i]) {
case "%d":
var day = date[i];
break;
case "%m":
var month = date[i] - 1;
break;
case "%Y":
var year = date[i];
break;
case "%y":
var year = date[i];
break;
}
++i;
};
return new Date(year, month, day);
}
// ----------------------------------------------------------------------------
// Get the computed style for and element
// ----------------------------------------------------------------------------