Bug 1301655 - pt 8 - Replace use of nsIScriptableDateFormat in toolkit/extensions code. r=gandalf
authorJonathan Kew <jkew@mozilla.com>
Fri, 28 Oct 2016 12:04:07 +0100
changeset 319935 8e2d25bd70b8412864e5005ea4099eb53f183d5c
parent 319934 17efbf713de8bb8f672340ef87cf0e78e5565232
child 319936 58dbf93c50dafeadab27fced867ab2b2717e57db
push id83271
push userjkew@mozilla.com
push dateFri, 28 Oct 2016 11:07:26 +0000
treeherdermozilla-inbound@686282bd2f19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgandalf
bugs1301655
milestone52.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1301655 - pt 8 - Replace use of nsIScriptableDateFormat in toolkit/extensions code. r=gandalf
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/content/extensions.xml
toolkit/mozapps/extensions/test/browser/head.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -1544,24 +1544,21 @@ function openOptionsInTab(optionsURL) {
   if ("switchToTabHavingURI" in mainWindow) {
     mainWindow.switchToTabHavingURI(optionsURL, true);
     return true;
   }
   return false;
 }
 
 function formatDate(aDate) {
-  return Cc["@mozilla.org/intl/scriptabledateformat;1"]
-           .getService(Ci.nsIScriptableDateFormat)
-           .FormatDate("",
-                       Ci.nsIScriptableDateFormat.dateFormatLong,
-                       aDate.getFullYear(),
-                       aDate.getMonth() + 1,
-                       aDate.getDate()
-                       );
+  const locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
+                 .getService(Ci.nsIXULChromeRegistry)
+                 .getSelectedLocale("global", true);
+  const dtOptions = { year: 'numeric', month: 'long', day: 'numeric' };
+  return aDate.toLocaleDateString(locale, dtOptions);
 }
 
 
 function hasPermission(aAddon, aPerm) {
   var perm = AddonManager["PERM_CAN_" + aPerm.toUpperCase()];
   return !!(aAddon.permissions & perm);
 }
 
--- a/toolkit/mozapps/extensions/content/extensions.xml
+++ b/toolkit/mozapps/extensions/content/extensions.xml
@@ -1160,24 +1160,21 @@
                                           this.mManualUpdate.releaseNotesURI :
                                           this.mAddon.releaseNotesURI);
         ]]></body>
       </method>
 
       <method name="_updateDates">
         <body><![CDATA[
           function formatDate(aDate) {
-            return Cc["@mozilla.org/intl/scriptabledateformat;1"]
-                     .getService(Ci.nsIScriptableDateFormat)
-                     .FormatDate("",
-                                 Ci.nsIScriptableDateFormat.dateFormatLong,
-                                 aDate.getFullYear(),
-                                 aDate.getMonth() + 1,
-                                 aDate.getDate()
-                                 );
+            const locale = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
+                           .getService(Components.interfaces.nsIXULChromeRegistry)
+                           .getSelectedLocale("global", true);
+            const dtOptions = { year: 'numeric', month: 'long', day: 'numeric' };
+            return aDate.toLocaleDateString(locale, dtOptions);
           }
 
           if (this.mAddon.updateDate)
             this._dateUpdated.value = formatDate(this.mAddon.updateDate);
           else
             this._dateUpdated.value = this._dateUpdated.getAttribute("unknown");
         ]]></body>
       </method>
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -499,24 +499,21 @@ function wait_for_window_open(aCallback)
 function get_string(aName, ...aArgs) {
   var bundle = Services.strings.createBundle("chrome://mozapps/locale/extensions/extensions.properties");
   if (aArgs.length == 0)
     return bundle.GetStringFromName(aName);
   return bundle.formatStringFromName(aName, aArgs, aArgs.length);
 }
 
 function formatDate(aDate) {
-  return Cc["@mozilla.org/intl/scriptabledateformat;1"]
-           .getService(Ci.nsIScriptableDateFormat)
-           .FormatDate("",
-                       Ci.nsIScriptableDateFormat.dateFormatLong,
-                       aDate.getFullYear(),
-                       aDate.getMonth() + 1,
-                       aDate.getDate()
-                       );
+  const locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
+                 .getService(Ci.nsIXULChromeRegistry)
+                 .getSelectedLocale("global", true);
+  const dtOptions = { year: 'numeric', month: 'long', day: 'numeric' };
+  return aDate.toLocaleDateString(locale, dtOptions);
 }
 
 function is_hidden(aElement) {
   var style = aElement.ownerDocument.defaultView.getComputedStyle(aElement, "");
   if (style.display == "none")
     return true;
   if (style.visibility != "visible")
     return true;