Bug 1505435 - Switch date-picker from Intl.DateTimeFormat to mozIMozIntl. r+a=jorgk
authorJonathan Kamens <jik@kamens.us>
Thu, 08 Nov 2018 18:08:00 +0100
changeset 33492 40efa95a8ab09a06f4e8778bfdb1dfad8a940c3c
parent 33491 76b887c99b713bd0dd4f358e6f4f65d3aad15d6b
child 33493 c40e51472fab2871b47789f9d9be2b3c2441e62e
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
bugs1505435
Bug 1505435 - Switch date-picker from Intl.DateTimeFormat to mozIMozIntl. r+a=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;
             }