Skip to content

Commit 511b86b

Browse files
committed
Merge pull request #201 from kzys/trac-7062
Fixed #7062 - $.datepicker.parseDate does not work for some locale date strings.
2 parents 0678d60 + a891e81 commit 511b86b

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

tests/unit/datepicker/datepicker.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<script type="text/javascript" src="../../../ui/jquery.ui.datepicker.js"></script>
1313
<script type="text/javascript" src="../../../ui/i18n/jquery.ui.datepicker-fr.js"></script>
1414
<script type="text/javascript" src="../../../ui/i18n/jquery.ui.datepicker-he.js"></script>
15+
<script type="text/javascript" src="../../../ui/i18n/jquery.ui.datepicker-zh-CN.js"></script>
1516

1617
<link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
1718
<script type="text/javascript" src="../../../external/qunit.js"></script>

tests/unit/datepicker/datepicker_options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,10 @@ test('parseDate', function() {
827827
equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy',
828828
'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9),
829829
'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings');
830+
831+
var zh = $.datepicker.regional['zh-CN'];
832+
equalsDate($.datepicker.parseDate('yy M d', '2011 十一 22', zh),
833+
new Date(2011, 11 - 1, 22), 'Parse date yy M d with zh-CN');
830834
});
831835

832836
test('parseDateErrors', function() {

ui/jquery.ui.datepicker.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -996,14 +996,24 @@ $.extend(Datepicker.prototype, {
996996
};
997997
// Extract a name from the string value and convert to an index
998998
var getName = function(match, shortNames, longNames) {
999-
var names = (lookAhead(match) ? longNames : shortNames);
1000-
for (var i = 0; i < names.length; i++) {
1001-
if (value.substr(iValue, names[i].length).toLowerCase() == names[i].toLowerCase()) {
1002-
iValue += names[i].length;
1003-
return i + 1;
999+
var names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
1000+
return [ [k, v] ];
1001+
}).sort(function (a, b) {
1002+
return -(a[1].length - b[1].length);
1003+
});
1004+
var index = -1;
1005+
$.each(names, function (i, pair) {
1006+
var name = pair[1];
1007+
if (value.substr(iValue, name.length).toLowerCase() == name.toLowerCase()) {
1008+
index = pair[0];
1009+
iValue += name.length;
1010+
return false;
10041011
}
1005-
}
1006-
throw 'Unknown name at position ' + iValue;
1012+
});
1013+
if (index != -1)
1014+
return index + 1;
1015+
else
1016+
throw 'Unknown name at position ' + iValue;
10071017
};
10081018
// Confirm that a literal character matches the string value
10091019
var checkLiteral = function() {

0 commit comments

Comments
 (0)