From b9c50d4bdd4fb5b4a5d889308fc9e421ae38568a Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Fri, 28 Oct 2016 12:04:07 +0100 Subject: [PATCH] Bug 1301655 - pt 4 - Replace use of nsIScriptableDateFormat with Date.toLocaleString in toolkit Update history. r=gandalf --- .../in-content/tests/browser_advanced_update.js | 17 ++++++----------- toolkit/mozapps/update/content/history.js | 17 ++++++----------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/browser/components/preferences/in-content/tests/browser_advanced_update.js b/browser/components/preferences/in-content/tests/browser_advanced_update.js index 1dc3a32548b1..e9d0e86521e2 100644 --- a/browser/components/preferences/in-content/tests/browser_advanced_update.js +++ b/browser/components/preferences/in-content/tests/browser_advanced_update.js @@ -8,8 +8,6 @@ const { classes: Cc, interfaces: Ci, manager: Cm, utils: Cu, results: Cr } = Com 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", @@ -87,15 +85,12 @@ function resetPreferences() { 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); diff --git a/toolkit/mozapps/update/content/history.js b/toolkit/mozapps/update/content/history.js index 624fd8a869dd..32a098de5322 100644 --- a/toolkit/mozapps/update/content/history.js +++ b/toolkit/mozapps/update/content/history.js @@ -58,18 +58,13 @@ var gUpdateHistory = { * @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); } };