Skip to content
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Datepicker: Handle date with years in range 0-99
  • Loading branch information
MoonE committed Mar 14, 2026
commit 11430738ea9e9435841aa9f742b63a9e776ae8ee
21 changes: 17 additions & 4 deletions ui/widgets/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,8 @@ $.extend( Datepicker.prototype, {
day = -1,
doy = -1,
literal = false,
length = -1,
isFromFullYear = false,
date,

// Check whether a format character is doubled
Expand All @@ -1242,7 +1244,8 @@ $.extend( Datepicker.prototype, {
if ( !num ) {
throw "Missing number at position " + iValue;
}
iValue += num[ 0 ].length;
length = num[ 0 ].length;
iValue += length;
return parseInt( num[ 0 ], 10 );
},

Expand Down Expand Up @@ -1304,18 +1307,21 @@ $.extend( Datepicker.prototype, {
break;
case "y":
year = getNumber( "y" );
isFromFullYear = length === 4;
break;
case "@":
date = new Date( getNumber( "@" ) );
year = date.getFullYear();
month = date.getMonth() + 1;
day = date.getDate();
isFromFullYear = true;
break;
case "!":
date = new Date( ( getNumber( "!" ) - this._ticksTo1970 ) / 10000 );
year = date.getFullYear();
month = date.getMonth() + 1;
day = date.getDate();
isFromFullYear = true;
break;
case "'":
if ( lookAhead( "'" ) ) {
Expand All @@ -1339,7 +1345,7 @@ $.extend( Datepicker.prototype, {

if ( year === -1 ) {
year = new Date().getFullYear();
} else if ( year < 100 ) {
} else if ( year < 100 && !isFromFullYear ) {
year += new Date().getFullYear() - new Date().getFullYear() % 100 +
( year <= shortYearCutoff ? 0 : -100 );
}
Expand Down Expand Up @@ -2172,9 +2178,16 @@ $.extend( Datepicker.prototype, {
return this.formatDate( this._get( inst, "dateFormat" ), date, this._getFormatConfig( inst ) );
},

/** Create a date object */
/** Create a date object with the correct year for years 0 through 99 */
_createDate: function( year, month, day ) {
return new Date( year, month, day );
var dateObject;
if ( year >= 0 && year < 100 ) {
dateObject = new Date( 2000, month, day );
dateObject.setFullYear( year );
} else {
dateObject = new Date( year, month, day );
}
return dateObject;
}
} );

Expand Down