Bug 488627 - Datepicker doesn't work with some short date formats. r=enn
authorMike Conley <mconley@mozilla.com>
Wed, 05 Oct 2011 17:26:11 -0400
changeset 78164 79dc3f1ea63a278a01531a6fbdb274a2362ff714
parent 78163 b3eb8258da6e3d7ee67066fa5fcd9b4e2a625ea3
child 78165 f7cf12c7ae3802b35840a655ddc0ac98c66f8db6
push id2407
push usermconley@mozilla.com
push dateWed, 05 Oct 2011 21:33:01 +0000
treeherdermozilla-inbound@79dc3f1ea63a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenn
bugs488627
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 488627 - Datepicker doesn't work with some short date formats. r=enn
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>