Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tests/unit/datepicker/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ QUnit.test( "keystrokes", function( assert ) {
} );

QUnit.test( "mouse", function( assert ) {
assert.expect( 15 );
assert.expect( 16 );
var inl,
inp = testHelper.init( "#inp" ),
dp = $( "#ui-datepicker-div" ),
Expand All @@ -481,6 +481,13 @@ QUnit.test( "mouse", function( assert ) {
$( "button.ui-datepicker-close", dp ).simulate( "click", {} );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 2008, 2 - 1, 4 ),
"Mouse click - abandoned" );
inp.datepicker( "hide" );

inp.val( "02/24/0999" ).datepicker( "show" );
$( ".ui-datepicker-calendar tbody a:contains(15)", dp ).simulate( "click", {} );
inp.datepicker( "show" );
testHelper.equalsDate( assert, inp.datepicker( "getDate" ), new Date( 999, 2 - 1, 15 ), "Mouse click inline - preset year 999" );
inp.datepicker( "hide" );

// Current/previous/next
inp.val( "02/04/2008" ).datepicker( "option", { showButtonPanel: true } ).datepicker( "show" );
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/datepicker/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ QUnit.test( "Ticket #7244: date parser does not fail when too many numbers are p
} );

QUnit.test( "formatDate", function( assert ) {
assert.expect( 16 );
assert.expect( 21 );
testHelper.init( "#inp" );
var gmtDate, fr, settings;
assert.equal( $.datepicker.formatDate( "d m y", new Date( 2001, 2 - 1, 3 ) ),
Expand Down Expand Up @@ -1164,6 +1164,14 @@ QUnit.test( "formatDate", function( assert ) {
assert.equal( $.datepicker.formatDate( "'jour' d 'de' MM (''DD''), yy",
new Date( 2001, 4 - 1, 9 ), settings ), "jour 9 de avril ('lundi'), 2001",
"Format date 'jour' d 'de' MM (''DD''), yy with settings" );

assert.equal( $.datepicker.formatDate( "yy-mm-dd", new Date( 100, 0, 1 ) ), "0100-01-01" );
assert.equal( $.datepicker.formatDate( "yy-mm-dd", new Date( 999, 0, 1 ) ), "0999-01-01" );
assert.equal( $.datepicker.formatDate( "yy-mm-dd", new Date( 1000, 0, 1 ) ), "1000-01-01" );

// -1 and 100000 will not be parsed correctly, but can be selected
assert.equal( $.datepicker.formatDate( "yy-mm-dd", new Date( -1, 0, 1 ) ), "-1-01-01" );
assert.equal( $.datepicker.formatDate( "yy-mm-dd", new Date( 10000, 0, 1 ) ), "10000-01-01" );
} );

// TODO: Fix this test so it isn't mysteriously flaky in Browserstack on certain OS/Browser combos
Expand Down
7 changes: 5 additions & 2 deletions ui/widgets/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ $.extend( Datepicker.prototype, {
dayNames = ( settings ? settings.dayNames : null ) || this._defaults.dayNames,
monthNamesShort = ( settings ? settings.monthNamesShort : null ) || this._defaults.monthNamesShort,
monthNames = ( settings ? settings.monthNames : null ) || this._defaults.monthNames,
year,

// Check whether a format character is doubled
lookAhead = function( match ) {
Expand Down Expand Up @@ -1474,8 +1475,10 @@ $.extend( Datepicker.prototype, {
output += formatName( "M", date.getMonth(), monthNamesShort, monthNames );
break;
case "y":
output += ( lookAhead( "y" ) ? date.getFullYear() :
( date.getFullYear() % 100 < 10 ? "0" : "" ) + date.getFullYear() % 100 );
year = date.getFullYear();
output += ( lookAhead( "y" ) ?
( year >= 0 && year < 1000 ? ( year < 10 ? "000" : year < 100 ? "00" : "0" ) : "" ) + year :
( year % 100 < 10 ? "0" : "" ) + year % 100 );
break;
case "@":
output += date.getTime();
Expand Down