Bug 1354445 - Migrate Intl.DateTimeFormat to mozIntl.DateTimeFormat in chrome. r?jfkthame draft
authorZibi Braniecki <gandalf@mozilla.com>
Sat, 08 Apr 2017 23:04:32 -0700
changeset 559888 07b488b64c3bfdda70f267e0af7ce7eaacd85b92
parent 558406 22df0c5cfbf8a2aa2822bf9c763e6c1c5a3f69de
child 623548 d9278e5ae6939fe68bd40d7557746c94169a6e22
push id53257
push userzbraniecki@mozilla.com
push dateMon, 10 Apr 2017 19:09:28 +0000
reviewersjfkthame
bugs1354445
milestone55.0a1
Bug 1354445 - Migrate Intl.DateTimeFormat to mozIntl.DateTimeFormat in chrome. r?jfkthame MozReview-Commit-ID: 4z13lcLXN9T
browser/base/content/content.js
browser/base/content/test/general/browser_aboutCertError.js
browser/components/feeds/FeedWriter.js
browser/components/places/content/places.js
browser/components/places/content/treeView.js
browser/components/places/tests/chrome/test_treeview_date.xul
toolkit/components/passwordmgr/LoginManagerContent.jsm
toolkit/components/passwordmgr/LoginManagerContextMenu.jsm
toolkit/components/passwordmgr/content/passwordManager.js
toolkit/crashreporter/content/crashes.js
toolkit/modules/Services.jsm
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -347,17 +347,20 @@ var AboutNetAndCertErrorListener = {
         // to give the user an approximation of what the correct time is.
         let difference = 0;
         if (Services.prefs.getPrefType(PREF_BLOCKLIST_CLOCK_SKEW_SECONDS)) {
           difference = Services.prefs.getIntPref(PREF_BLOCKLIST_CLOCK_SKEW_SECONDS);
         }
 
         // If the difference is more than a day.
         if (Math.abs(difference) > 60 * 60 * 24) {
-          let formatter = new Intl.DateTimeFormat();
+          let formatter = Services.intl.createDateTimeFormat(undefined, {
+            dateStyle: "long",
+            timeStyle: "short",
+          });
           let systemDate = formatter.format(new Date());
           // negative difference means local time is behind server time
           let actualDate = formatter.format(new Date(Date.now() - difference * 1000));
 
           content.document.getElementById("wrongSystemTime_URL")
             .textContent = content.document.location.hostname;
           content.document.getElementById("wrongSystemTime_systemDate")
             .textContent = systemDate;
@@ -377,17 +380,20 @@ var AboutNetAndCertErrorListener = {
           let year = parseInt(appBuildID.substr(0, 4), 10);
           let month = parseInt(appBuildID.substr(4, 2), 10) - 1;
           let day = parseInt(appBuildID.substr(6, 2), 10);
 
           let buildDate = new Date(year, month, day);
           let systemDate = new Date();
 
           if (buildDate > systemDate) {
-            let formatter = new Intl.DateTimeFormat();
+            let formatter = Services.intl.createDateTimeFormat(undefined,{
+              dateStyle: 'long',
+              timeStyle: 'medium',
+            });
 
             content.document.getElementById("wrongSystemTimeWithoutReference_URL")
               .textContent = content.document.location.hostname;
             content.document.getElementById("wrongSystemTimeWithoutReference_systemDate")
               .textContent = formatter.format(systemDate);
 
             content.document.getElementById("errorShortDesc")
               .style.display = "none";
--- a/browser/base/content/test/general/browser_aboutCertError.js
+++ b/browser/base/content/test/general/browser_aboutCertError.js
@@ -146,17 +146,20 @@ add_task(function* checkWrongSystemTimeW
         text: div.textContent,
         systemDate: systemDateDiv.textContent,
         actualDate: actualDateDiv.textContent,
         learnMoreLink: learnMoreLink.href
       };
     });
   }
 
-  let formatter = new Intl.DateTimeFormat();
+  let formatter = Services.intl.createDateTimeFormat(undefined, {
+    dateStyle: 'long',
+    timeStyle: 'short'
+  });
 
   // pretend we have a positively skewed (ahead) system time
   let serverDate = new Date("2015/10/27");
   let serverDateFmt = formatter.format(serverDate);
   let localDateFmt = formatter.format(new Date());
 
   let skew = Math.floor((Date.now() - serverDate.getTime()) / 1000);
   yield SpecialPowers.pushPrefEnv({set: [[PREF_BLOCKLIST_CLOCK_SKEW_SECONDS, skew]]});
--- a/browser/components/feeds/FeedWriter.js
+++ b/browser/components/feeds/FeedWriter.js
@@ -184,19 +184,21 @@ FeedWriter.prototype = {
       return false;
 
     return this._dateFormatter.format(dateObj);
   },
 
   __dateFormatter: null,
   get _dateFormatter() {
     if (!this.__dateFormatter) {
-      const dtOptions = { year: "numeric", month: "long", day: "numeric",
-                          hour: "numeric", minute: "numeric" };
-      this.__dateFormatter = new Intl.DateTimeFormat(undefined, dtOptions);
+      const dtOptions = {
+        timeStyle: "short",
+        dateStyle: "long"
+      }
+      this.__dateFormatter = Services.intl.createDateTimeFormat(undefined, dtOptions);
     }
     return this.__dateFormatter;
   },
 
   /**
    * Returns the feed type.
    */
   __feedType: null,
--- a/browser/components/places/content/places.js
+++ b/browser/components/places/content/places.js
@@ -5,16 +5,17 @@
 
 /* import-globals-from editBookmarkOverlay.js */
 // Via downloadsViewOverlay.xul -> allDownloadsViewOverlay.xul
 /* import-globals-from ../../../../toolkit/content/contentAreaUtils.js */
 
 Components.utils.import("resource://gre/modules/AppConstants.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/TelemetryStopwatch.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "MigrationUtils",
                                   "resource:///modules/MigrationUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
                                   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "BookmarkJSONUtils",
                                   "resource://gre/modules/BookmarkJSONUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
                                   "resource://gre/modules/PlacesBackups.jsm");
@@ -406,18 +407,20 @@ var PlacesOrganizer = {
   },
 
   /**
    * Populates the restore menu with the dates of the backups available.
    */
   populateRestoreMenu: function PO_populateRestoreMenu() {
     let restorePopup = document.getElementById("fileRestorePopup");
 
-    const dtOptions = { year: "numeric", month: "long", day: "numeric" };
-    let dateFormatter = new Intl.DateTimeFormat(undefined, dtOptions);
+    const dtOptions = {
+      dateStyle: "long"
+    };
+    let dateFormatter = Services.intl.createDateTimeFormat(undefined, dtOptions);
 
     // Remove existing menu items.  Last item is the restoreFromFile item.
     while (restorePopup.childNodes.length > 1)
       restorePopup.firstChild.remove();
 
     Task.spawn(function* () {
       let backupFiles = yield PlacesBackups.getBackupFiles();
       if (backupFiles.length == 0)
--- a/browser/components/places/content/treeView.js
+++ b/browser/components/places/content/treeView.js
@@ -1,13 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
 const PTV_interfaces = [Ci.nsITreeView,
                         Ci.nsINavHistoryResultObserver,
                         Ci.nsINavHistoryResultTreeViewer,
                         Ci.nsISupportsWeakReference];
 
 function PlacesTreeView(aFlatList, aOnOpenFlatContainer, aController) {
   this._tree = null;
@@ -494,28 +495,30 @@ PlacesTreeView.prototype = {
                               : this._dateFormatter.format(timeObj);
   },
 
   // We use a different formatter for times within the current day,
   // so we cache both a "today" formatter and a general date formatter.
   __todayFormatter: null,
   get _todayFormatter() {
     if (!this.__todayFormatter) {
-      const dtOptions = { hour: "numeric", minute: "numeric" };
-      this.__todayFormatter = new Intl.DateTimeFormat(undefined, dtOptions);
+      const dtOptions = { timeStyle: "short" };
+      this.__todayFormatter = Services.intl.createDateTimeFormat(undefined, dtOptions);
     }
     return this.__todayFormatter;
   },
 
   __dateFormatter: null,
   get _dateFormatter() {
     if (!this.__dateFormatter) {
-      const dtOptions = { year: "numeric", month: "numeric", day: "numeric",
-                          hour: "numeric", minute: "numeric" };
-      this.__dateFormatter = new Intl.DateTimeFormat(undefined, dtOptions);
+      const dtOptions = {
+        dateStyle: "short",
+        timeStyle: "short"
+      }
+      this.__dateFormatter = Services.intl.createDateTimeFormat(undefined, dtOptions);
     }
     return this.__dateFormatter;
   },
 
   COLUMN_TYPE_UNKNOWN: 0,
   COLUMN_TYPE_TITLE: 1,
   COLUMN_TYPE_URI: 2,
   COLUMN_TYPE_DATE: 3,
--- a/browser/components/places/tests/chrome/test_treeview_date.xul
+++ b/browser/components/places/tests/chrome/test_treeview_date.xul
@@ -119,28 +119,31 @@
                   is(text, node.title, "Title is correct");
                 break;
               case "url":
                 is(text, node.uri, "Uri is correct");
                 break;
               case "date":
                 let timeObj = new Date(node.time / 1000);
                 // Default is short date format.
-                let dtOptions = { year: 'numeric', month: 'numeric', day: 'numeric',
-                                  hour: 'numeric', minute: 'numeric' };
+                let dtOptions = {
+                  dateStyle: "short",
+                  timeStyle: "short"
+                }
+
                 // For today's visits we don't show date portion.
                 if (node.uri == "http://at.midnight.com/" ||
                     node.uri == "http://after.midnight.com/") {
-                  dtOptions = { hour: 'numeric', minute: 'numeric' };
+                  dtOptions.dateStyle = undefined;
                 } else if (node.uri != "http://before.midnight.com/") {
                   // Avoid to test spurious uris, due to how the test works
                   // a redirecting uri could be put in the tree while we test.
                   break;
                 }
-                let timeStr = timeObj.toLocaleString(undefined, dtOptions);
+                let timeStr = Services.intl.createDateTimeFormat(undefined, dtOptions).format(timeObj);
 
                 is(text, timeStr, "Date format is correct");
                 break;
               case "visitCount":
                 is(text, 1, "Visit count is correct");
                 break;
             }
           }
--- a/toolkit/components/passwordmgr/LoginManagerContent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerContent.jsm
@@ -1438,18 +1438,17 @@ function UserAutoCompleteResult(aSearchS
   }
 
   this._showInsecureFieldWarning = (!isSecure && LoginHelper.showInsecureFieldWarning) ? 1 : 0;
   this.searchString = aSearchString;
   this.logins = matchingLogins.sort(loginSort);
   this.matchCount = matchingLogins.length + this._showInsecureFieldWarning;
   this._messageManager = messageManager;
   this._stringBundle = Services.strings.createBundle("chrome://passwordmgr/locale/passwordmgr.properties");
-  this._dateAndTimeFormatter = new Intl.DateTimeFormat(undefined,
-                              { day: "numeric", month: "short", year: "numeric" });
+  this._dateAndTimeFormatter = Services.intl.createDateTimeFormat(undefined, { dateStyle: "medium" });
 
   this._isPasswordField = isPasswordField;
 
   this._duplicateUsernames = findDuplicates(matchingLogins);
 
   if (this.matchCount > 0) {
     this.searchResult = Ci.nsIAutoCompleteResult.RESULT_SUCCESS;
     this.defaultIndex = 0;
--- a/toolkit/components/passwordmgr/LoginManagerContextMenu.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerContextMenu.jsm
@@ -186,14 +186,12 @@ var LoginManagerContextMenu = {
 };
 
 XPCOMUtils.defineLazyGetter(LoginManagerContextMenu, "_stringBundle", function() {
   return Services.strings.
          createBundle("chrome://passwordmgr/locale/passwordmgr.properties");
 });
 
 XPCOMUtils.defineLazyGetter(LoginManagerContextMenu, "dateAndTimeFormatter", function() {
-  return new Intl.DateTimeFormat(undefined, {
-    day: "numeric",
-    month: "short",
-    year: "numeric",
+  return Services.intl.createDateTimeFormat(undefined, {
+    dateStyle: "medium"
   });
 });
--- a/toolkit/components/passwordmgr/content/passwordManager.js
+++ b/toolkit/components/passwordmgr/content/passwordManager.js
@@ -54,21 +54,21 @@ let signonReloadDisplay = {
           break;
       }
       Services.obs.notifyObservers(null, "passwordmgr-dialog-updated", null);
     }
   }
 };
 
 // Formatter for localization.
-let dateFormatter = new Intl.DateTimeFormat(undefined,
-                      { day: "numeric", month: "short", year: "numeric" });
-let dateAndTimeFormatter = new Intl.DateTimeFormat(undefined,
-                             { day: "numeric", month: "short", year: "numeric",
-                               hour: "numeric", minute: "numeric" });
+let dateFormatter = Services.intl.createDateTimeFormat(undefined,
+                      { dateStyle: "medium" });
+let dateAndTimeFormatter = Services.intl.createDateTimeFormat(undefined,
+                             { dateStyle: "medium",
+                               timeStyle: "short" });
 
 function Startup() {
   // be prepared to reload the display if anything changes
   Services.obs.addObserver(signonReloadDisplay, "passwordmgr-storage-changed", false);
 
   signonsTree = document.getElementById("signonsTree");
   kSignonBundle = document.getElementById("signonBundle");
   filterField = document.getElementById("filter");
--- a/toolkit/crashreporter/content/crashes.js
+++ b/toolkit/crashreporter/content/crashes.js
@@ -73,21 +73,18 @@ function populateReportList() {
     document.getElementById("reportList").style.display = "none";
     document.getElementById("noReports").style.display = "block";
     return;
   }
 
   var dateFormatter;
   var timeFormatter;
   try {
-    dateFormatter = new Intl.DateTimeFormat(undefined, { year: "2-digit",
-                                                         month: "numeric",
-                                                         day: "numeric" });
-    timeFormatter = new Intl.DateTimeFormat(undefined, { hour: "numeric",
-                                                         minute: "numeric" });
+    dateFormatter = Services.intl.createDateTimeFormat(undefined, { dateStyle: "short" });
+    timeFormatter = Services.intl.createDateTimeFormat(undefined, { timeStyle: "short" });
   } catch (e) {
     // XXX Fallback to be removed once bug 1215247 is complete
     // and the Intl API is available on all platforms.
     dateFormatter = {
       format(date) {
         return date.toLocaleDateString();
       }
     }
--- a/toolkit/modules/Services.jsm
+++ b/toolkit/modules/Services.jsm
@@ -70,16 +70,17 @@ var initTable = [
   ["console", "@mozilla.org/consoleservice;1", "nsIConsoleService"],
   ["contentPrefs", "@mozilla.org/content-pref/service;1", "nsIContentPrefService"],
   ["cookies", "@mozilla.org/cookiemanager;1", "nsICookieManager2"],
   ["downloads", "@mozilla.org/download-manager;1", "nsIDownloadManager"],
   ["droppedLinkHandler", "@mozilla.org/content/dropped-link-handler;1", "nsIDroppedLinkHandler"],
   ["els", "@mozilla.org/eventlistenerservice;1", "nsIEventListenerService"],
   ["eTLD", "@mozilla.org/network/effective-tld-service;1", "nsIEffectiveTLDService"],
   ["io", "@mozilla.org/network/io-service;1", "nsIIOService2"],
+  ["intl", "@mozilla.org/mozintl;1", "mozIMozIntl"],
   ["locale", "@mozilla.org/intl/localeservice;1", "mozILocaleService"],
   ["logins", "@mozilla.org/login-manager;1", "nsILoginManager"],
   ["obs", "@mozilla.org/observer-service;1", "nsIObserverService"],
   ["perms", "@mozilla.org/permissionmanager;1", "nsIPermissionManager"],
   ["prompt", "@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService"],
   ["profiler", "@mozilla.org/tools/profiler;1", "nsIProfiler",
    AppConstants.MOZ_GECKO_PROFILER],
   ["scriptloader", "@mozilla.org/moz/jssubscript-loader;1", "mozIJSSubScriptLoader"],