diff --git a/calendar/resources/content/dateUtils.js b/calendar/resources/content/dateUtils.js index 1e76ef3cfa2..0b0e91fceef 100644 --- a/calendar/resources/content/dateUtils.js +++ b/calendar/resources/content/dateUtils.js @@ -282,7 +282,34 @@ DateFormater.prototype.getShortDayName = function( dayIndex ) return dayName; } - +DateFormater.prototype.parseShortDate = function ( dateString ) +{ + // probe for date format -- this part could be in constructor + // probe result state: + var parseShortDateRegex = /^\s*(\d+)\D(\d+)\D(\d+)\s*$/; //digits & nonDigits + var parsedYearIndex = -1, parsedMonthIndex = -1, parsedDayIndex = -1; + { // do probe + var probeDate = new Date(2002,3-1,4); // month is 0-based + var probeString = this.getShortFormatedDate(probeDate); + + var probeArray = parseShortDateRegex.exec(probeString); + for (var i = 1; i <= 3; i++) { + switch (Number(probeArray[i])) { + case 2002: case 02: parsedYearIndex = i; break; + case 3: parsedMonthIndex = i; break; + case 4: parsedDayIndex = i; break; + } + } + // all three parsed indexes are now set (no longer -1) + } + // parse dateString + var dateNumbersArray = parseShortDateRegex.exec(dateString); + if (dateNumbersArray != null) { + return new Date(Number(dateNumbersArray[parsedYearIndex]), + 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 aeadbfea05a..44b9c6ff4ec 100644 --- a/calendar/resources/content/datepicker/datepicker.xml +++ b/calendar/resources/content/datepicker/datepicker.xml @@ -10,8 +10,8 @@ + onkeypress="if (event.keyCode == 13) this.parentNode.parentNode.update(new DateFormater().parseShortDate(this.value));" + onblur="this.parentNode.parentNode.parentNode.parentNode.update(new DateFormater().parseShortDate(this.value),true);"/> @@ -37,6 +37,7 @@ this.mTextBox = document.getAnonymousNodes(this)[0].childNodes[0]; this.mPopup = document.getAnonymousNodes(this)[0].childNodes[1].childNodes[0]; this.calendar = document.getAnonymousNodes(this)[0].childNodes[1].childNodes[0].childNodes[0]; + this.formatter= new DateFormater(); var val = this.getAttribute("value"); @@ -76,7 +77,7 @@