Skip to content

Commit 9728bc4

Browse files
committed
Datepicker: Handle date with years in range 0-99
1 parent 59d41d2 commit 9728bc4

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

ui/widgets/datepicker.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,8 @@ $.extend( Datepicker.prototype, {
12201220
day = -1,
12211221
doy = -1,
12221222
literal = false,
1223+
length = -1,
1224+
isFromFullYear = false,
12231225
date,
12241226

12251227
// Check whether a format character is doubled
@@ -1242,7 +1244,8 @@ $.extend( Datepicker.prototype, {
12421244
if ( !num ) {
12431245
throw "Missing number at position " + iValue;
12441246
}
1245-
iValue += num[ 0 ].length;
1247+
length = num[ 0 ].length;
1248+
iValue += length;
12461249
return parseInt( num[ 0 ], 10 );
12471250
},
12481251

@@ -1304,18 +1307,21 @@ $.extend( Datepicker.prototype, {
13041307
break;
13051308
case "y":
13061309
year = getNumber( "y" );
1310+
isFromFullYear = length === 4;
13071311
break;
13081312
case "@":
13091313
date = new Date( getNumber( "@" ) );
13101314
year = date.getFullYear();
13111315
month = date.getMonth() + 1;
13121316
day = date.getDate();
1317+
isFromFullYear = true;
13131318
break;
13141319
case "!":
13151320
date = new Date( ( getNumber( "!" ) - this._ticksTo1970 ) / 10000 );
13161321
year = date.getFullYear();
13171322
month = date.getMonth() + 1;
13181323
day = date.getDate();
1324+
isFromFullYear = true;
13191325
break;
13201326
case "'":
13211327
if ( lookAhead( "'" ) ) {
@@ -1339,7 +1345,7 @@ $.extend( Datepicker.prototype, {
13391345

13401346
if ( year === -1 ) {
13411347
year = new Date().getFullYear();
1342-
} else if ( year < 100 ) {
1348+
} else if ( year < 100 && !isFromFullYear ) {
13431349
year += new Date().getFullYear() - new Date().getFullYear() % 100 +
13441350
( year <= shortYearCutoff ? 0 : -100 );
13451351
}
@@ -2174,9 +2180,16 @@ $.extend( Datepicker.prototype, {
21742180
return this.formatDate( this._get( inst, "dateFormat" ), date, this._getFormatConfig( inst ) );
21752181
},
21762182

2177-
/** Create a date object */
2183+
/** Create a date object with the correct year for years 0 through 99 */
21782184
_createDate: function( year, month, day ) {
2179-
return new Date( year, month, day );
2185+
var dateObject = new Date( year, month, day );
2186+
if ( year >= 0 && year < 100 ) {
2187+
dateObject.setDate( 1 );
2188+
dateObject.setFullYear( year );
2189+
dateObject.setMonth( month );
2190+
dateObject.setDate( day );
2191+
}
2192+
return dateObject;
21802193
}
21812194
} );
21822195

0 commit comments

Comments
 (0)