Bug 1505435 - Switch date-picker from Intl.DateTimeFormat to mozIMozIntl. r=jorgk
authorJonathan Kamens <jik@kamens.us>
Thu, 08 Nov 2018 18:08:00 +0100
changeset 33683 38005533aabc57fce5b64a865d965fa64bea4bfe
parent 33682 3f3b0b711dbbb498e57cf6cd43ce5f50e09c59a6
child 33684 6c2e0403281d6cb7babeceaade2c54227363402a
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersjorgk
bugs1505435
Bug 1505435 - Switch date-picker from Intl.DateTimeFormat to mozIMozIntl. r=jorgk
common/bindings/datetimepicker.xml
--- a/common/bindings/datetimepicker.xml
+++ b/common/bindings/datetimepicker.xml
@@ -483,30 +483,31 @@
         <body>
           <![CDATA[
             this.hourField = this._fieldOne;
             this.minuteField = this._fieldTwo;
             this.secondField = this._fieldThree;
 
             var numberOrder = /^(\D*)\s*(\d+)(\D*)(\d+)(\D*)(\d+)\s*(\D*)$/;
 
-            var locale = Intl.DateTimeFormat().resolvedOptions().locale + "-u-ca-gregory-nu-latn";
+            var locale = Services.locale.regionalPrefsLocales[0] + "-u-ca-gregory-nu-latn";
+            var dtf = new Services.intl.DateTimeFormat(locale, { timeStyle: "long" });
 
-            var pmTime = new Date(2000, 0, 1, 16, 7, 9).toLocaleTimeString(locale);
+            var pmTime = dtf.format(new Date(2000, 0, 1, 16, 7, 9));
             var numberFields = pmTime.match(numberOrder);
             if (numberFields) {
               this._separatorFirst.value = numberFields[3];
               this._separatorSecond.value = numberFields[5];
               if (Number(numberFields[2]) > 12)
                 this.is24HourClock = true;
               else
                 this.pmIndicator = numberFields[1] || numberFields[7];
             }
 
-            var amTime = new Date(2000, 0, 1, 1, 7, 9).toLocaleTimeString(locale);
+            var amTime = dtf.format(new Date(2000, 0, 1, 1, 7, 9));
             numberFields = amTime.match(numberOrder);
             if (numberFields) {
               this.hourLeadingZero = (numberFields[2].length > 1);
               this.minuteLeadingZero = (numberFields[4].length > 1);
               this.secondLeadingZero = (numberFields[6].length > 1);
 
               if (!this.is24HourClock) {
                 this.amIndicator = numberFields[1] || numberFields[7];
@@ -771,19 +772,20 @@
             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 locale = Intl.DateTimeFormat().resolvedOptions().locale + "-u-ca-gregory-nu-latn";
+            var locale = Services.locale.regionalPrefsLocales[0] + "-u-ca-gregory-nu-latn";
+            var dtf = new Services.intl.DateTimeFormat(locale, { dateStyle: "short" });
 
-            var dt = new Date(2002, 9, 4).toLocaleDateString(locale);
+            var dt = dtf.format(new Date(2002, 9, 4));
             var numberFields = dt.match(numberOrder);
             if (numberFields) {
               this._separatorFirst.value = numberFields[3];
               this._separatorSecond.value = numberFields[5];
 
               var yi = 2, mi = 4, di = 6;
 
               function fieldForNumber(i) {
@@ -1001,19 +1003,19 @@
           this._updateUI(this.yearField, val, true);
           return val;
         </setter>
       </property>
 
       <method name="_init">
         <body>
           <![CDATA[
-            var locale = Intl.DateTimeFormat().resolvedOptions().locale + "-u-ca-gregory";
-            var dtfMonth = Intl.DateTimeFormat(locale, {month: "long", timeZone: "UTC"});
-            var dtfWeekday = Intl.DateTimeFormat(locale, {weekday: "narrow"});
+            var locale = Services.locale.regionalPrefsLocales[0] + "-u-ca-gregory";
+            var dtfMonth = new Services.intl.DateTimeFormat(locale, {month: "long", timeZone: "UTC"});
+            var dtfWeekday = new Services.intl.DateTimeFormat(locale, {weekday: "narrow"});
 
             var monthLabel = this.monthField.firstChild;
             var tempDate = new Date(Date.UTC(2005, 0, 1));
             for (var month = 0; month < 12; month++) {
               tempDate.setUTCMonth(month);
               monthLabel.setAttribute("value", dtfMonth.format(tempDate));
               monthLabel = monthLabel.nextSibling;
             }