Bug 1313795 - Remove Date.prototype.toLocaleFormat uses in toolkit/content/widgets. r=Neil
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 01 Nov 2016 09:20:48 -0700
changeset 347588 88013961312c001ea61e2ed0d89855bd02382069
parent 347587 6e4a31120b5362746102351b70776636ffb0e689
child 347589 7d4a5ed8adf14b7b7b7adabb9028634e3d0cec31
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs1313795
milestone52.0a1
Bug 1313795 - Remove Date.prototype.toLocaleFormat uses in toolkit/content/widgets. r=Neil
toolkit/content/tests/chrome/test_timepicker.xul
toolkit/content/widgets/datetimepicker.xml
--- a/toolkit/content/tests/chrome/test_timepicker.xul
+++ b/toolkit/content/tests/chrome/test_timepicker.xul
@@ -38,17 +38,18 @@ function testtag_timepicker()
 
   // testtag_comparetime(tp, testid + "initial", thour, tminute, tsecond);
 
   // check that setting the value property works
   tp.value = testtag_gettimestring(thour, tminute, tsecond);
   testtag_comparetime(tp, testid + "set value", thour, tminute, tsecond);
 
   var numberOrder = /^(\D*)\s*(\d+)(\D*)(\d+)(\D*)(\d+)\s*(\D*)$/;
-  var fdt = new Date(2000,0,1,16,7,9).toLocaleFormat("%X");
+  var locale = Intl.DateTimeFormat().resolvedOptions().locale + "-u-ca-gregory-nu-latn";
+  var fdt = new Date(2000,0,1,16,7,9).toLocaleTimeString(locale);
   is(tp.is24HourClock, Number(fdt.match(numberOrder)[2]) > 12, "is24HourClock");
 
   // check that setting the dateValue property works
   tp.dateValue = today;
   testtag_comparetime(tp, testid + "set dateValue", thour, tminute, tsecond);
   ok(tp.value !== today, testid + " set dateValue different time");
 
   ok(!tp.readOnly, testid + "readOnly");
--- a/toolkit/content/widgets/datetimepicker.xml
+++ b/toolkit/content/widgets/datetimepicker.xml
@@ -477,28 +477,30 @@
         <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 pmTime = new Date(2000, 0, 1, 16, 7, 9).toLocaleFormat("%X");
+            var locale = Intl.DateTimeFormat().resolvedOptions().locale + "-u-ca-gregory-nu-latn";
+
+            var pmTime = new Date(2000, 0, 1, 16, 7, 9).toLocaleTimeString(locale);
             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).toLocaleFormat("%X");
+            var amTime = new Date(2000, 0, 1, 1, 7, 9).toLocaleTimeString(locale);
             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];
@@ -765,17 +767,19 @@
             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 locale = Intl.DateTimeFormat().resolvedOptions().locale + "-u-ca-gregory-nu-latn";
+
+            var dt = new Date(2002, 9, 4).toLocaleDateString(locale);
             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) {
@@ -989,33 +993,37 @@
           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"});
+            var dtfWeekday = Intl.DateTimeFormat(locale, {weekday: "narrow"});
+
             var monthLabel = this.monthField.firstChild;
             var tempDate = new Date(2005, 0, 1);
             for (var month = 0; month < 12; month++) {
               tempDate.setMonth(month);
-              monthLabel.setAttribute("value", tempDate.toLocaleFormat("%B"));
+              monthLabel.setAttribute("value", dtfMonth.format(tempDate));
               monthLabel = monthLabel.nextSibling;
             }
 
             var fdow = Number(this.getAttribute("firstdayofweek"));
             if (!isNaN(fdow) && fdow >= 0 && fdow <= 6)
               this._weekStart = fdow;
 
             var weekbox = document.getAnonymousElementByAttribute(this, "anonid", "dayofweekbox").childNodes;
             var date = new Date();
             date.setDate(date.getDate() - (date.getDay() - this._weekStart));
             for (var i = 0; i < weekbox.length; i++) {
-              weekbox[i].value = date.toLocaleFormat("%a").charAt(0);
+              weekbox[i].value = dtfWeekday.format(date);
               date.setDate(date.getDate() + 1);
             }
           ]]>
         </body>
       </method>
       <method name="_setValueNoSync">
         <parameter name="aValue"/>
         <body>