Bug 488627 - Fix datepicker to work nicely with more date formats. r=enn, a=legneato.
authorMike Conley <mconley@mozilla.com>
Fri, 07 Oct 2011 15:04:48 -0400
changeset 79065 b3b15c400d3fcb18181b7486db461e4d9f31b8db
parent 79064 5cbbdef702d3290d76226eb2bea7a5f6a2bbc913
child 79066 a929601e7a9e873d5afe95090c1688cf323e9cbf
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenn, legneato
bugs488627
milestone9.0a2
Bug 488627 - Fix datepicker to work nicely with more date formats. r=enn, a=legneato.
toolkit/content/widgets/datetimepicker.xml
--- a/toolkit/content/widgets/datetimepicker.xml
+++ b/toolkit/content/widgets/datetimepicker.xml
@@ -786,29 +786,35 @@
               return aNoWrap ? max : min;
             return aValue;
           ]]>
         </body>
       </method>
       <method name="_init">
         <body>
           <![CDATA[
+            // We'll default to YYYY/MM/DD to start.
+            var yfield = "input-one";
+            var mfield = "input-two";
+            var dfield = "input-three";
+            var twoDigitYear = false;
+            this.yearLeadingZero = true;
+            this.monthLeadingZero = true;
+            this.dateLeadingZero = true;
+
             var numberOrder = /^(\D*)\s*(\d+)(\D*)(\d+)(\D*)(\d+)\s*(\D*)$/;
 
             var dt = new Date(2002,9,4).toLocaleFormat("%x");
             var numberFields = dt.match(numberOrder);
             if (numberFields) {
               this._separatorFirst.value = numberFields[3];
               this._separatorSecond.value = numberFields[5];
 
-              var twoDigitYear = false;
-              var yfield = "input-one";
-              var mfield = "input-two";
-              var dfield = "input-three";
               var yi = 2, mi = 4, di = 6;
+
               for (var i = 1; i < numberFields.length; i++) {
                 switch (Number(numberFields[i])) {
                   case 2:
                     twoDigitYear = true; // fall through
                   case 2002:
                     yi = i;
                     yfield = (i == 2 ? "input-one" :
                              (i == 4 ? "input-two" : "input-three"));
@@ -820,29 +826,29 @@
                     break;
                   case 4:
                     di = i;
                     dfield = (i == 2 ? "input-one" :
                              (i == 4 ? "input-two" : "input-three"));
                     break;
                 }
               }
+
+              this.yearLeadingZero = (numberFields[yi].length > 1);
+              this.monthLeadingZero = (numberFields[mi].length > 1);
+              this.dateLeadingZero = (numberFields[di].length > 1);
             }
 
             this.yearField = document.getAnonymousElementByAttribute(this, "anonid", yfield);
             if (!twoDigitYear)
               this.yearField.parentNode.className =
                 "datetimepicker-input-subbox datetimepicker-year";
             this.monthField = document.getAnonymousElementByAttribute(this, "anonid", mfield);
             this.dateField = document.getAnonymousElementByAttribute(this, "anonid", dfield);
 
-            this.yearLeadingZero = (numberFields[yi].length > 1);
-            this.monthLeadingZero = (numberFields[mi].length > 1);
-            this.dateLeadingZero = (numberFields[di].length > 1);
-
             this._fieldAMPM.parentNode.collapsed = true;
             this.yearField.size = twoDigitYear ? 2 : 4;
             this.yearField.maxLength = twoDigitYear ? 2 : 4;
           ]]>
         </body>
       </method>
     </implementation>