Datepicker: Greedy matching in month name. Fixed #7062 - $.datepicker.parseDate does not work for some locale date strings.

This commit is contained in:
Kato Kazuyoshi 2011-05-05 05:06:27 +09:00
parent fd1b4f84fe
commit a891e81e06
3 changed files with 22 additions and 7 deletions

View File

@ -12,6 +12,7 @@
<script type="text/javascript" src="../../../ui/jquery.ui.datepicker.js"></script> <script type="text/javascript" src="../../../ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="../../../ui/i18n/jquery.ui.datepicker-fr.js"></script> <script type="text/javascript" src="../../../ui/i18n/jquery.ui.datepicker-fr.js"></script>
<script type="text/javascript" src="../../../ui/i18n/jquery.ui.datepicker-he.js"></script> <script type="text/javascript" src="../../../ui/i18n/jquery.ui.datepicker-he.js"></script>
<script type="text/javascript" src="../../../ui/i18n/jquery.ui.datepicker-zh-CN.js"></script>
<link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/> <link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
<script type="text/javascript" src="../../../external/qunit.js"></script> <script type="text/javascript" src="../../../external/qunit.js"></script>

View File

@ -827,6 +827,10 @@ test('parseDate', function() {
equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy', equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy',
'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9), 'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9),
'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings'); 'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings');
var zh = $.datepicker.regional['zh-CN'];
equalsDate($.datepicker.parseDate('yy M d', '2011 十一 22', zh),
new Date(2011, 11 - 1, 22), 'Parse date yy M d with zh-CN');
}); });
test('parseDateErrors', function() { test('parseDateErrors', function() {

View File

@ -996,14 +996,24 @@ $.extend(Datepicker.prototype, {
}; };
// Extract a name from the string value and convert to an index // Extract a name from the string value and convert to an index
var getName = function(match, shortNames, longNames) { var getName = function(match, shortNames, longNames) {
var names = (lookAhead(match) ? longNames : shortNames); var names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
for (var i = 0; i < names.length; i++) { return [ [k, v] ];
if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) { }).sort(function (a, b) {
iValue += names[i].length; return -(a[1].length - b[1].length);
return i + 1; });
var index = -1;
$.each(names, function (i, pair) {
var name = pair[1];
if (value.substr(iValue, name.length).toLowerCase() == name.toLowerCase()) {
index = pair[0];
iValue += name.length;
return false;
} }
} });
throw 'Unknown name at position ' + iValue; if (index != -1)
return index + 1;
else
throw 'Unknown name at position ' + iValue;
}; };
// Confirm that a literal character matches the string value // Confirm that a literal character matches the string value
var checkLiteral = function() { var checkLiteral = function() {