Bug 1521454 - Follow-up: Avoid exception due to bad locale code when appending [-u]-ca-gregory-nu-latn (more call sites). r+a=jorgk
authorArrigo Marchiori <ardovm@yahoo.it>
Fri, 08 Feb 2019 10:33:00 +0100
changeset 34319 175d46dcc1ce8acc6fc3060235a936061e861403
parent 34318 99bc32d53976fa2e087dbc40d7121cea3fbfc5fd
child 34320 a7c0ece1f2274bf442e9e764aaa07e980d89befe
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
bugs1521454
Bug 1521454 - Follow-up: Avoid exception due to bad locale code when appending [-u]-ca-gregory-nu-latn (more call sites). r+a=jorgk
common/bindings/datetimepicker.xml
--- a/common/bindings/datetimepicker.xml
+++ b/common/bindings/datetimepicker.xml
@@ -779,17 +779,22 @@
             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 = Services.locale.regionalPrefsLocales[0] + "-u-ca-gregory-nu-latn";
+            // XXX TODO: The following hack should be fixed once Intl.Locale arrives in bug 1433303.
+            var locale = Services.locale.regionalPrefsLocales[0];
+            if (locale.includes("-u-"))
+              locale += "-ca-gregory-nu-latn";
+            else
+              locale += "-u-ca-gregory-nu-latn";
             var dtf = new Services.intl.DateTimeFormat(locale, { dateStyle: "short" });
 
             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];
 
@@ -1010,17 +1015,22 @@
           this._updateUI(this.yearField, val, true);
           return val;
         </setter>
       </property>
 
       <method name="_init">
         <body>
           <![CDATA[
-            var locale = Services.locale.regionalPrefsLocales[0] + "-u-ca-gregory";
+            // XXX TODO: The following hack should be fixed once Intl.Locale arrives in bug 1433303.
+            var locale = Services.locale.regionalPrefsLocales[0];
+            if (locale.includes("-u-"))
+              locale += "-ca-gregory";
+            else
+              locale += "-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));