зеркало из https://github.com/mozilla/pjs.git
Checking in patches for bug 185394: Date picker format does not respect local settings
This commit is contained in:
Родитель
901d06bf68
Коммит
1247d87de2
|
@ -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
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
<!-- ::::::::::::::::: CONTENT ::::::::::::::::::::::::: -->
|
||||
<content id="content">
|
||||
<xul:hbox flex="1" id="hbox">
|
||||
<xul:textbox id="textbox"
|
||||
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);"/>
|
||||
<xul:textbox id="textbox"
|
||||
onkeypress="if (event.keyCode == 13) this.parentNode.parentNode.parseTextDate();"
|
||||
onblur="this.parentNode.parentNode.parentNode.parentNode.parseTextDate(true);"/>
|
||||
|
||||
<xul:menu class="datepicker-button">
|
||||
<xul:menupopup popupanchor="bottomright" popupalign="topright" onpopupshowing="this.parentNode.parentNode.parentNode.openPopup()">
|
||||
|
@ -55,11 +55,12 @@
|
|||
<parameter name="aValue"/>
|
||||
<parameter name="refresh"/>
|
||||
<body><![CDATA[
|
||||
if (!aValue || aValue.toString() == "Invalid Date") {
|
||||
this.mTextBox.setAttribute("value", this.getPrettyDate(this.mValue));
|
||||
if (aValue == null) { // invalid date, revert to previous date
|
||||
// set textBox.value property, not attribute
|
||||
this.mTextBox.value = this.getPrettyDate(this.mValue);
|
||||
} else {
|
||||
this.mValue = aValue;
|
||||
this.mTextBox.setAttribute("value", this.getPrettyDate(this.mValue));
|
||||
this.mTextBox.value = this.getPrettyDate(this.mValue);
|
||||
if( this.callback && refresh != false )
|
||||
this.callback();
|
||||
}
|
||||
|
@ -81,6 +82,12 @@
|
|||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="parseTextDate">
|
||||
<parameter name="aRefresh"/>
|
||||
<body><![CDATA[
|
||||
this.update(this.formatter.parseShortDate(this.mTextBox.value), aRefresh);
|
||||
]]></body>
|
||||
</method>
|
||||
<method name="openPopup">
|
||||
<body><![CDATA[
|
||||
this.calendar.update( this.mValue );
|
||||
|
|
Загрузка…
Ссылка в новой задаче