зеркало из 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:
Родитель
bb1b555dcd
Коммит
1f75332632
|
@ -282,7 +282,34 @@ DateFormater.prototype.getShortDayName = function( dayIndex )
|
||||||
return dayName;
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
<content id="content">
|
<content id="content">
|
||||||
<xul:hbox flex="1" id="hbox">
|
<xul:hbox flex="1" id="hbox">
|
||||||
<xul:textbox id="textbox"
|
<xul:textbox id="textbox"
|
||||||
onkeypress="if (event.keyCode == 13) this.parentNode.parentNode.update(new Date(this.value));"
|
onkeypress="if (event.keyCode == 13) this.parentNode.parentNode.update(new DateFormater().parseShortDate(this.value));"
|
||||||
onblur="this.parentNode.parentNode.parentNode.parentNode.update(new Date(this.value),true);"/>
|
onblur="this.parentNode.parentNode.parentNode.parentNode.update(new DateFormater().parseShortDate(this.value),true);"/>
|
||||||
|
|
||||||
<xul:menu class="datepicker-button">
|
<xul:menu class="datepicker-button">
|
||||||
<xul:menupopup popupanchor="bottomright" popupalign="topright" oncreate="this.parentNode.parentNode.parentNode.parentNode.openPopup()">
|
<xul:menupopup popupanchor="bottomright" popupalign="topright" oncreate="this.parentNode.parentNode.parentNode.parentNode.openPopup()">
|
||||||
|
@ -37,6 +37,7 @@
|
||||||
this.mTextBox = document.getAnonymousNodes(this)[0].childNodes[0];
|
this.mTextBox = document.getAnonymousNodes(this)[0].childNodes[0];
|
||||||
this.mPopup = document.getAnonymousNodes(this)[0].childNodes[1].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.calendar = document.getAnonymousNodes(this)[0].childNodes[1].childNodes[0].childNodes[0];
|
||||||
|
this.formatter= new DateFormater();
|
||||||
|
|
||||||
var val = this.getAttribute("value");
|
var val = this.getAttribute("value");
|
||||||
|
|
||||||
|
@ -76,7 +77,7 @@
|
||||||
<method name="getPrettyDate">
|
<method name="getPrettyDate">
|
||||||
<parameter name="aValue"/>
|
<parameter name="aValue"/>
|
||||||
<body><![CDATA[
|
<body><![CDATA[
|
||||||
return (aValue.getMonth()+1) + "/" + aValue.getDate() + "/" + aValue.getFullYear();
|
return this.formatter.getShortFormatedDate(aValue);
|
||||||
]]></body>
|
]]></body>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче