--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -350,17 +350,19 @@ 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: "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;
@@ -380,17 +382,19 @@ 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: "short"
+ });
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,19 @@ 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: "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/components/passwordmgr/test/mochitest/test_password_field_autocomplete.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_password_field_autocomplete.html
@@ -89,16 +89,19 @@ var setupScript = runInParent(function s
<button type="submit">Submit</button>
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
+let { Services } =
+ SpecialPowers.Cu.import("resource://gre/modules/Services.jsm", {});
+
/** Test for Login Manager: multiple login autocomplete. **/
var uname = $_(1, "uname");
var pword = $_(1, "pword");
const shiftModifier = SpecialPowers.Ci.nsIDOMEvent.SHIFT_MASK;
// Restore the form to the default state.
function* reinitializeForm(index) {
@@ -123,18 +126,18 @@ function* reinitializeForm(index) {
uname = $_(index, "uname");
pword = $_(index, "pword");
uname.value = "";
pword.value = "";
pword.focus();
}
function generateDateString(date) {
- let dateAndTimeFormatter = new Intl.DateTimeFormat(undefined,
- { day: "numeric", month: "short", year: "numeric" });
+ let dateAndTimeFormatter = Services.intl.createDateTimeFormat(undefined,
+ { dateStyle: "medium" });
return dateAndTimeFormatter.format(date);
}
const DATE_NOW_STRING = generateDateString(new Date());
// Check for expected username/password in form.
function checkACFormPasswordField(expectedPassword) {
var formID = uname.parentNode.id;
--- a/toolkit/components/passwordmgr/test/unit/test_context_menu.js
+++ b/toolkit/components/passwordmgr/test/unit/test_context_menu.js
@@ -97,18 +97,18 @@ function checkLoginItems(logins, items)
duplicates.add(login.username);
}
seen.add(login.username);
}
return duplicates;
}
let duplicates = findDuplicates(logins);
- let dateAndTimeFormatter = new Intl.DateTimeFormat(undefined,
- { day: "numeric", month: "short", year: "numeric" });
+ let dateAndTimeFormatter = Services.intl.createDateTimeFormat(undefined,
+ { dateStyle: "medium" });
for (let login of logins) {
if (login.username && !duplicates.has(login.username)) {
// If login is not duplicate and we can't find an item for it, fail.
if (!items.find(item => item.label == login.username)) {
return false;
}
continue;
}
--- a/toolkit/components/passwordmgr/test/unit/test_user_autocomplete_result.js
+++ b/toolkit/components/passwordmgr/test/unit/test_user_autocomplete_result.js
@@ -19,18 +19,18 @@ matchingLogins.push(new nsLoginInfo("htt
matchingLogins.push(new nsLoginInfo("http://mochi.test:8888", "http://autocomplete:8888", null,
"testuser3", "testpass3", "uname", "pword"));
matchingLogins.push(new nsLoginInfo("http://mochi.test:8888", "http://autocomplete:8888", null,
"zzzuser4", "zzzpass4", "uname", "pword"));
let meta = matchingLogins[0].QueryInterface(Ci.nsILoginMetaInfo);
-let dateAndTimeFormatter = new Intl.DateTimeFormat(undefined,
- { day: "numeric", month: "short", year: "numeric" });
+let dateAndTimeFormatter = Services.intl.createDateTimeFormat(undefined,
+ { dateStyle: "medium" });
let time = dateAndTimeFormatter.format(new Date(meta.timePasswordChanged));
const LABEL_NO_USERNAME = "No username (" + time + ")";
let expectedResults = [
{
insecureFieldWarningEnabled: true,
insecureAutoFillFormsEnabled: true,
isSecure: true,
--- 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"],
--- a/toolkit/modules/tests/xpcshell/test_Services.js
+++ b/toolkit/modules/tests/xpcshell/test_Services.js
@@ -40,16 +40,17 @@ function run_test() {
checkService("DOMRequest", Ci.nsIDOMRequestService);
checkService("domStorageManager", Ci.nsIDOMStorageManager);
checkService("downloads", Ci.nsIDownloadManager);
checkService("droppedLinkHandler", Ci.nsIDroppedLinkHandler);
checkService("eTLD", Ci.nsIEffectiveTLDService);
checkService("focus", Ci.nsIFocusManager);
checkService("io", Ci.nsIIOService);
checkService("io", Ci.nsIIOService2);
+ checkService("intl", Ci.mozIMozIntl);
checkService("locale", Ci.mozILocaleService);
checkService("logins", Ci.nsILoginManager);
checkService("obs", Ci.nsIObserverService);
checkService("perms", Ci.nsIPermissionManager);
checkService("prefs", Ci.nsIPrefBranch);
checkService("prefs", Ci.nsIPrefService);
checkService("prompt", Ci.nsIPromptService);
checkService("scriptSecurityManager", Ci.nsIScriptSecurityManager);