diff --git a/calendar/resources/content/dateUtils.js b/calendar/resources/content/dateUtils.js index 0b0e91fceef..d271da42c6e 100644 --- a/calendar/resources/content/dateUtils.js +++ b/calendar/resources/content/dateUtils.js @@ -288,6 +288,7 @@ DateFormater.prototype.parseShortDate = function ( dateString ) // probe result state: var parseShortDateRegex = /^\s*(\d+)\D(\d+)\D(\d+)\s*$/; //digits & nonDigits var parsedYearIndex = -1, parsedMonthIndex = -1, parsedDayIndex = -1; + var parseTwoDigitYear = false; { // do probe var probeDate = new Date(2002,3-1,4); // month is 0-based var probeString = this.getShortFormatedDate(probeDate); @@ -295,7 +296,8 @@ DateFormater.prototype.parseShortDate = function ( dateString ) var probeArray = parseShortDateRegex.exec(probeString); for (var i = 1; i <= 3; i++) { switch (Number(probeArray[i])) { - case 2002: case 02: parsedYearIndex = i; break; + case 02: parseTwoDigitYear = true; // fall thru + case 2002: parsedYearIndex = i; break; case 3: parsedMonthIndex = i; break; case 4: parsedDayIndex = i; break; } @@ -305,7 +307,19 @@ DateFormater.prototype.parseShortDate = function ( dateString ) // parse dateString var dateNumbersArray = parseShortDateRegex.exec(dateString); if (dateNumbersArray != null) { - return new Date(Number(dateNumbersArray[parsedYearIndex]), + var year = Number(dateNumbersArray[parsedYearIndex]); + if (parseTwoDigitYear && 0 <= year && year < 100) { + // If 2-digit year format and 0 <= year < 100, + // parse year as up to 30 years in future or 69 years in past. + // (Covers 30-year mortgage and most working people's birthdate.) + // otherwise will be treated as four digit year. + var currentYear = 1900 + new Date().getYear(); // getYear 0 is 1900. + var currentCentury = currentYear - currentYear % 100; + year = currentCentury + year; + if (year > currentYear + 30) + year -= 100; + } + return new Date(year, // four-digit year Number(dateNumbersArray[parsedMonthIndex]) - 1, // 0-based Number(dateNumbersArray[parsedDayIndex])); } else return null; // did not match regex, not a valid date diff --git a/calendar/resources/content/datepicker/datepicker.xml b/calendar/resources/content/datepicker/datepicker.xml index 2fb2074e8a4..b7345bf6a09 100644 --- a/calendar/resources/content/datepicker/datepicker.xml +++ b/calendar/resources/content/datepicker/datepicker.xml @@ -9,9 +9,9 @@ - + @@ -55,11 +55,12 @@ + + + +