Bug 1503731 - Avoid timezone conversion for date pattern detection of the datetimepicker; r=philipp
☠☠ backed out by d2d18de2ec85 ☠ ☠
authorMakeMyDay <makemyday@gmx-topmail.de>
Sat, 17 Nov 2018 12:19:14 +0100
changeset 34033 66eedcaff9fac89a318dd866d42b3777e32e58c4
parent 34032 3df0e93306f9092a25631f9c7558cceb577fa9d8
child 34034 04d7082e573a71f892831c1078c8ee03dd0e4207
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersphilipp
bugs1503731
Bug 1503731 - Avoid timezone conversion for date pattern detection of the datetimepicker; r=philipp
calendar/resources/content/datetimepickers/datetimepickers.xml
--- a/calendar/resources/content/datetimepickers/datetimepickers.xml
+++ b/calendar/resources/content/datetimepickers/datetimepickers.xml
@@ -1661,18 +1661,21 @@
             this.alphaMonths = null;
             this.probeSucceeded = false;
             this.mLastDateParseIncludedTime = false;
 
             // SHORT NUMERIC DATE, such as 2002-03-04, 4/3/2002, or CE2002Y03M04D.
             // Made of digits & nonDigits.  (Nondigits may be unicode letters
             // which do not match \w, esp. in CJK locales.)
             this.parseShortDateRegex = /^\D*(\d+)\D+(\d+)\D+(\d+)\D?$/;
-            let probeDate = new Date(2002, 2, 4); // month is 0-based
-            let probeString = this.formatDate(probeDate);
+            // Make sure to use UTC date and timezone here to avoid the pattern
+            // detection to fail if the probe date output would have an timezone
+            // offset due to our lack of support of historic timezone definitions.
+            let probeDate = new Date(Date.UTC(2002, 2, 4)); // month is 0-based
+            let probeString = this.formatDate(probeDate, cal.dtz.utc);
             let probeArray = this.parseShortDateRegex.exec(probeString);
             if (probeArray) {
                 // Numeric month format
                 for (let i = 1; i <= 3; i++) {
                     switch (Number(probeArray[i])) {
                         case 2: this.twoDigitYear = true; // falls through
                         case 2002: this.yearIndex = i; break;
                         case 3: this.monthIndex = i; break;
@@ -1831,18 +1834,24 @@
                 new RegExp("(" + ampmExpr + ")?\\s?" + digitsExpr + "(" + ampmExpr + ")?\\s*$");
             this.amRegExp = new RegExp("^(?:" + amExpr + ")$");
             this.pmRegExp = new RegExp("^(?:" + pmExpr + ")$");
         ]]></body>
       </method>
 
       <method name="formatDate">
         <parameter name="aDate"/>
+        <parameter name="aTimezone"/>
         <body><![CDATA[
-            return cal.getDateFormatter().formatDateShort(cal.dtz.jsDateToDateTime(aDate, cal.dtz.floating));
+            // Usually, floating is ok here, so no need to pass aTimezone - we just need to pass
+            // it in if we need to make sure formatting happens without a timezone conversion.
+            let timezone = aTimezone || cal.dtz.floating;
+            return cal.getDateFormatter().formatDateShort(
+                cal.dtz.jsDateToDateTime(aDate, timezone)
+            );
         ]]></body>
       </method>
 
       <method name="formatTime">
         <parameter name="aValue"/>
         <body><![CDATA[
             let formatter = new Services.intl.DateTimeFormat(undefined, this.kTimeFormatObject);
             return formatter.format(aValue);