Bug 1389791: timepicker changes pm to am when it shouldn't. r=aceman
authorJonathan Kamens <jik@kamens.us>
Wed, 21 Mar 2018 08:31:26 -0400
changeset 23562 99d37d6cd81b2a68db336b192a03018dcb01d6f0
parent 23561 0a725681fe43d87d975b068a3394bd0cd27c1b84
child 23563 2b766c4599492395710e64a653220628ad72dc62
push id14224
push usermozilla@jorgk.com
push dateWed, 21 Mar 2018 16:44:09 +0000
treeherdercomm-central@2b766c459949 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs1389791
Bug 1389791: timepicker changes pm to am when it shouldn't. r=aceman Fix the following bug: 1. Instantiate an XUL timepicker object. 2. Change the time in the timepicker so that it reads, e.g., 2:43 PM. 3. Highlight the hour portion of the picker and change the 2 to a 5. 4. Hit tab. 5. Observe that the "PM" changes to "AM". There's no reason whatsoever why "PM" should change to "AM" here. It's etirely incorrect and nonintuitive behavior.
common/bindings/datetimepicker.xml
--- a/common/bindings/datetimepicker.xml
+++ b/common/bindings/datetimepicker.xml
@@ -432,25 +432,22 @@
         <body>
           <![CDATA[
             this._valueEntered = false;
 
             var prependZero = false;
             if (aField == this.hourField) {
               prependZero = this.hourLeadingZero;
               if (!this.is24HourClock) {
-                if (aValue >= 12) {
-                  if (aValue > 12)
-                    aValue -= 12;
-                  this._fieldAMPM.value = this.pmIndicator;
-                } else {
-                  if (aValue == 0)
-                    aValue = 12;
-                  this._fieldAMPM.value = this.amIndicator;
-                }
+                if (aValue > 12)
+                  aValue -= 12;
+                else if (aValue == 0)
+                  aValue = 12;
+                this._fieldAMPM.value = this.isPM ? this.pmIndicator :
+                  this.amIndicator;
               }
             } else if (aField == this.minuteField) {
               prependZero = this.minuteLeadingZero;
             } else if (aField == this.secondField) {
               prependZero = this.secondLeadingZero;
             }
 
             if (prependZero && aValue < 10)
@@ -464,17 +461,28 @@
         <parameter name="aField"/>
         <parameter name="aValue"/>
         <parameter name="aNoWrap"/>
         <body>
           <![CDATA[
             // aNoWrap is true when the user entered a value, so just
             // constrain within limits. If false, the value is being
             // incremented or decremented, so wrap around values
-            var max = (aField == this.hourField) ? 24 : 60;
+            var max = 60;
+            if (aField == this.hourField) {
+              max = 24;
+              // User input in the hour field should be adjusted as
+              // needed for 12-hour vs. 24-hour time.
+              if (aNoWrap && !this.is24HourClock) {
+                if (aValue && aValue < 12 && this.isPM)
+                  aValue += 12;
+                else if (aValue == 12 && !this.isPM)
+                  aValue = 0;
+              }
+            }
             if (aValue < 0)
               return aNoWrap ? 0 : max + aValue;
             if (aValue >= max)
               return aNoWrap ? max - 1 : aValue - max;
             return aValue;
           ]]>
         </body>
       </method>