[Centaury] Replace usage of the ECMAScript Intl API in UI JS code with nsIScriptableDateFormat.
parent
0811addcc1
commit
cc7b21a59a
|
@ -1051,16 +1051,18 @@ function formatNumber(number)
|
||||||
|
|
||||||
function formatDate(datestr, unknown)
|
function formatDate(datestr, unknown)
|
||||||
{
|
{
|
||||||
|
// scriptable date formatter, for pretty printing dates
|
||||||
|
var dateService = Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
|
||||||
|
.getService(Components.interfaces.nsIScriptableDateFormat);
|
||||||
|
|
||||||
var date = new Date(datestr);
|
var date = new Date(datestr);
|
||||||
if (!date.valueOf())
|
if (!date.valueOf())
|
||||||
return unknown;
|
return unknown;
|
||||||
|
|
||||||
const locale = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
return dateService.FormatDateTime("", dateService.dateFormatLong,
|
||||||
.getService(Components.interfaces.nsIXULChromeRegistry)
|
dateService.timeFormatSeconds,
|
||||||
.getSelectedLocale("global", true);
|
date.getFullYear(), date.getMonth()+1, date.getDate(),
|
||||||
const dtOptions = { year: 'numeric', month: 'long', day: 'numeric',
|
date.getHours(), date.getMinutes(), date.getSeconds());
|
||||||
hour: 'numeric', minute: 'numeric', second: 'numeric' };
|
|
||||||
return date.toLocaleString(locale, dtOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doCopy()
|
function doCopy()
|
||||||
|
|
|
@ -185,20 +185,11 @@ FeedWriter.prototype = {
|
||||||
if (!dateObj.getTime())
|
if (!dateObj.getTime())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return this._dateFormatter.format(dateObj);
|
let dateService = Cc["@mozilla.org/intl/scriptabledateformat;1"].
|
||||||
},
|
getService(Ci.nsIScriptableDateFormat);
|
||||||
|
return dateService.FormatDateTime("", dateService.dateFormatLong, dateService.timeFormatNoSeconds,
|
||||||
__dateFormatter: null,
|
dateObj.getFullYear(), dateObj.getMonth()+1, dateObj.getDate(),
|
||||||
get _dateFormatter() {
|
dateObj.getHours(), dateObj.getMinutes(), dateObj.getSeconds());
|
||||||
if (!this.__dateFormatter) {
|
|
||||||
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' };
|
|
||||||
this.__dateFormatter = new Intl.DateTimeFormat(locale, dtOptions);
|
|
||||||
}
|
|
||||||
return this.__dateFormatter;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -409,11 +409,8 @@ var PlacesOrganizer = {
|
||||||
populateRestoreMenu: function() {
|
populateRestoreMenu: function() {
|
||||||
let restorePopup = document.getElementById("fileRestorePopup");
|
let restorePopup = document.getElementById("fileRestorePopup");
|
||||||
|
|
||||||
const locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
|
let dateSvc = Cc["@mozilla.org/intl/scriptabledateformat;1"].
|
||||||
.getService(Ci.nsIXULChromeRegistry)
|
getService(Ci.nsIScriptableDateFormat);
|
||||||
.getSelectedLocale("global", true);
|
|
||||||
const dtOptions = { year: 'numeric', month: 'long', day: 'numeric' };
|
|
||||||
let dateFormatter = new Intl.DateTimeFormat(locale, dtOptions);
|
|
||||||
|
|
||||||
// Remove existing menu items. Last item is the restoreFromFile item.
|
// Remove existing menu items. Last item is the restoreFromFile item.
|
||||||
while (restorePopup.childNodes.length > 1)
|
while (restorePopup.childNodes.length > 1)
|
||||||
|
@ -445,7 +442,13 @@ var PlacesOrganizer = {
|
||||||
let backupDate = PlacesBackups.getDateForFile(backupFiles[i]);
|
let backupDate = PlacesBackups.getDateForFile(backupFiles[i]);
|
||||||
let m = restorePopup.insertBefore(document.createElement("menuitem"),
|
let m = restorePopup.insertBefore(document.createElement("menuitem"),
|
||||||
document.getElementById("restoreFromFile"));
|
document.getElementById("restoreFromFile"));
|
||||||
m.setAttribute("label", dateFormatter.format(backupDate) + sizeInfo);
|
m.setAttribute("label",
|
||||||
|
dateSvc.FormatDate("",
|
||||||
|
Ci.nsIScriptableDateFormat.dateFormatLong,
|
||||||
|
backupDate.getFullYear(),
|
||||||
|
backupDate.getMonth() + 1,
|
||||||
|
backupDate.getDate()) +
|
||||||
|
sizeInfo);
|
||||||
m.setAttribute("value", OS.Path.basename(backupFiles[i]));
|
m.setAttribute("value", OS.Path.basename(backupFiles[i]));
|
||||||
m.setAttribute("oncommand",
|
m.setAttribute("oncommand",
|
||||||
"PlacesOrganizer.onRestoreMenuItemClick(this);");
|
"PlacesOrganizer.onRestoreMenuItemClick(this);");
|
||||||
|
|
|
@ -33,6 +33,15 @@ PlacesTreeView.prototype = {
|
||||||
return this.__xulStore;
|
return this.__xulStore;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
__dateService: null,
|
||||||
|
get _dateService() {
|
||||||
|
if (!this.__dateService) {
|
||||||
|
this.__dateService = Cc["@mozilla.org/intl/scriptabledateformat;1"].
|
||||||
|
getService(Ci.nsIScriptableDateFormat);
|
||||||
|
}
|
||||||
|
return this.__dateService;
|
||||||
|
},
|
||||||
|
|
||||||
QueryInterface: XPCOMUtils.generateQI(PTV_interfaces),
|
QueryInterface: XPCOMUtils.generateQI(PTV_interfaces),
|
||||||
|
|
||||||
// Bug 761494:
|
// Bug 761494:
|
||||||
|
@ -495,36 +504,16 @@ PlacesTreeView.prototype = {
|
||||||
let midnight = now - (now % MS_PER_DAY);
|
let midnight = now - (now % MS_PER_DAY);
|
||||||
midnight += new Date(midnight).getTimezoneOffset() * MS_PER_MINUTE;
|
midnight += new Date(midnight).getTimezoneOffset() * MS_PER_MINUTE;
|
||||||
|
|
||||||
|
let dateFormat = timeMs >= midnight ?
|
||||||
|
Ci.nsIScriptableDateFormat.dateFormatNone :
|
||||||
|
Ci.nsIScriptableDateFormat.dateFormatShort;
|
||||||
|
|
||||||
let timeObj = new Date(timeMs);
|
let timeObj = new Date(timeMs);
|
||||||
return timeMs >= midnight ? this._todayFormatter.format(timeObj)
|
return (this._dateService.FormatDateTime("", dateFormat,
|
||||||
: this._dateFormatter.format(timeObj);
|
Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
|
||||||
},
|
timeObj.getFullYear(), timeObj.getMonth() + 1,
|
||||||
|
timeObj.getDate(), timeObj.getHours(),
|
||||||
// We use a different formatter for times within the current day,
|
timeObj.getMinutes(), timeObj.getSeconds()));
|
||||||
// so we cache both a "today" formatter and a general date formatter.
|
|
||||||
__todayFormatter: null,
|
|
||||||
get _todayFormatter() {
|
|
||||||
if (!this.__todayFormatter) {
|
|
||||||
const locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
|
|
||||||
.getService(Ci.nsIXULChromeRegistry)
|
|
||||||
.getSelectedLocale("global", true);
|
|
||||||
const dtOptions = { hour: 'numeric', minute: 'numeric' };
|
|
||||||
this.__todayFormatter = new Intl.DateTimeFormat(locale, dtOptions);
|
|
||||||
}
|
|
||||||
return this.__todayFormatter;
|
|
||||||
},
|
|
||||||
|
|
||||||
__dateFormatter: null,
|
|
||||||
get _dateFormatter() {
|
|
||||||
if (!this.__dateFormatter) {
|
|
||||||
const locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
|
|
||||||
.getService(Ci.nsIXULChromeRegistry)
|
|
||||||
.getSelectedLocale("global", true);
|
|
||||||
const dtOptions = { year: 'numeric', month: 'numeric', day: 'numeric',
|
|
||||||
hour: 'numeric', minute: 'numeric' };
|
|
||||||
this.__dateFormatter = new Intl.DateTimeFormat(locale, dtOptions);
|
|
||||||
}
|
|
||||||
return this.__dateFormatter;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
COLUMN_TYPE_UNKNOWN: 0,
|
COLUMN_TYPE_UNKNOWN: 0,
|
||||||
|
|
|
@ -12,6 +12,8 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
var gCookiesWindow = {
|
var gCookiesWindow = {
|
||||||
_cm : Components.classes["@mozilla.org/cookiemanager;1"]
|
_cm : Components.classes["@mozilla.org/cookiemanager;1"]
|
||||||
.getService(Components.interfaces.nsICookieManager),
|
.getService(Components.interfaces.nsICookieManager),
|
||||||
|
_ds : Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
|
||||||
|
.getService(Components.interfaces.nsIScriptableDateFormat),
|
||||||
_hosts : {},
|
_hosts : {},
|
||||||
_hostOrder : [],
|
_hostOrder : [],
|
||||||
_tree : null,
|
_tree : null,
|
||||||
|
@ -490,12 +492,14 @@ var gCookiesWindow = {
|
||||||
formatExpiresString: function (aExpires) {
|
formatExpiresString: function (aExpires) {
|
||||||
if (aExpires) {
|
if (aExpires) {
|
||||||
var date = new Date(1000 * aExpires);
|
var date = new Date(1000 * aExpires);
|
||||||
const locale = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
return this._ds.FormatDateTime("", this._ds.dateFormatLong,
|
||||||
.getService(Components.interfaces.nsIXULChromeRegistry)
|
this._ds.timeFormatSeconds,
|
||||||
.getSelectedLocale("global", true);
|
date.getFullYear(),
|
||||||
const dtOptions = { year: 'numeric', month: 'long', day: 'numeric',
|
date.getMonth() + 1,
|
||||||
hour: 'numeric', minute: 'numeric', second: 'numeric' };
|
date.getDate(),
|
||||||
return date.toLocaleString(locale, dtOptions);
|
date.getHours(),
|
||||||
|
date.getMinutes(),
|
||||||
|
date.getSeconds());
|
||||||
}
|
}
|
||||||
return this._bundle.getString("expireAtEndOfSession");
|
return this._bundle.getString("expireAtEndOfSession");
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue