Bug 1301655 - pt 4 - Replace use of nsIScriptableDateFormat with Date.toLocaleString in toolkit Update history. r=gandalf
authorJonathan Kew <jkew@mozilla.com>
Fri, 28 Oct 2016 12:04:07 +0100
changeset 319992 59f24ab7fc079e573cbdb2fb8d828a951639e62a
parent 319991 68543a46ef49fb7309c345179c87912b8d75e41b
child 319993 48e81da5a95b8b2c53213a3675ce20d86df87a35
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgandalf
bugs1301655
milestone52.0a1
Bug 1301655 - pt 4 - Replace use of nsIScriptableDateFormat with Date.toLocaleString in toolkit Update history. r=gandalf
browser/components/preferences/in-content/tests/browser_advanced_update.js
toolkit/mozapps/update/content/history.js
--- a/browser/components/preferences/in-content/tests/browser_advanced_update.js
+++ b/browser/components/preferences/in-content/tests/browser_advanced_update.js
@@ -3,18 +3,16 @@
 
 "use strict";
 
 const { classes: Cc, interfaces: Ci, manager: Cm, utils: Cu, results: Cr } = Components;
 
 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
 
 const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
-const dateFormat = Cc["@mozilla.org/intl/scriptabledateformat;1"]
-                      .getService(Components.interfaces.nsIScriptableDateFormat);
 
 const mockUpdateManager = {
   contractId: "@mozilla.org/updates/update-manager;1",
 
   _mockClassId: uuidGenerator.generateUUID(),
 
   _originalClassId: "",
 
@@ -82,25 +80,22 @@ const mockUpdateManager = {
 };
 
 function resetPreferences() {
   Services.prefs.clearUserPref("browser.search.update");
 }
 
 function formatInstallDate(sec) {
   var date = new Date(sec);
-  return dateFormat.FormatDateTime("",
-    dateFormat.dateFormatLong,
-    dateFormat.timeFormatSeconds,
-    date.getFullYear(),
-    date.getMonth() + 1,
-    date.getDate(),
-    date.getHours(),
-    date.getMinutes(),
-    date.getSeconds());
+  const locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
+                 .getService(Ci.nsIXULChromeRegistry)
+                 .getSelectedLocale("global", true);
+  const dtOptions = { year: 'numeric', month: 'long', day: 'numeric',
+                      hour: 'numeric', minute: 'numeric', second: 'numeric' };
+  return date.toLocaleString(locale, dtOptions);
 }
 
 registerCleanupFunction(resetPreferences);
 
 add_task(function*() {
   yield openPreferencesViaOpenPreferencesAPI("advanced", "updateTab", { leaveOpen: true });
   resetPreferences();
   Services.prefs.setBoolPref("browser.search.update", false);
--- a/toolkit/mozapps/update/content/history.js
+++ b/toolkit/mozapps/update/content/history.js
@@ -53,23 +53,18 @@ var gUpdateHistory = {
 
   /**
    * Formats a date into human readable form
    * @param   seconds
    *          A date in seconds since 1970 epoch
    * @returns A human readable date string
    */
   _formatDate: function(seconds) {
-    var sdf =
-        Components.classes["@mozilla.org/intl/scriptabledateformat;1"].
-        getService(Components.interfaces.nsIScriptableDateFormat);
     var date = new Date(seconds);
-    return sdf.FormatDateTime("", sdf.dateFormatLong,
-                              sdf.timeFormatSeconds,
-                              date.getFullYear(),
-                              date.getMonth() + 1,
-                              date.getDate(),
-                              date.getHours(),
-                              date.getMinutes(),
-                              date.getSeconds());
+    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',
+                        hour: 'numeric', minute: 'numeric', second: 'numeric' };
+    return date.toLocaleString(locale, dtOptions);
   }
 };