summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-12-04 18:13:16 +0000
committerMoonchild <moonchild@palemoon.org>2020-12-04 18:13:16 +0000
commit5f972538cfdae60e03448cf4ca0ac28231ef1f03 (patch)
tree723c6e7f1c8bb5827f9f589faec25f3c9429dbc8
parent8a74eeb8ee67563d02ec6e3f74ddfc9ef8e65a14 (diff)
downloadbasilisk-5f972538cfdae60e03448cf4ca0ac28231ef1f03.tar.gz
Issue #31 - Part 3: Use nsIScriptableDateFormat in places library window.
-rw-r--r--basilisk/components/places/content/places.js15
-rw-r--r--basilisk/components/places/content/treeView.js47
2 files changed, 27 insertions, 35 deletions
diff --git a/basilisk/components/places/content/places.js b/basilisk/components/places/content/places.js
index c0df873..30b4b7b 100644
--- a/basilisk/components/places/content/places.js
+++ b/basilisk/components/places/content/places.js
@@ -409,11 +409,8 @@ var PlacesOrganizer = {
populateRestoreMenu: function() {
let restorePopup = document.getElementById("fileRestorePopup");
- const locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
- .getService(Ci.nsIXULChromeRegistry)
- .getSelectedLocale("global", true);
- const dtOptions = { year: 'numeric', month: 'long', day: 'numeric' };
- let dateFormatter = new Intl.DateTimeFormat(locale, dtOptions);
+ let dateSvc = Cc["@mozilla.org/intl/scriptabledateformat;1"].
+ getService(Ci.nsIScriptableDateFormat);
// Remove existing menu items. Last item is the restoreFromFile item.
while (restorePopup.childNodes.length > 1)
@@ -445,7 +442,13 @@ var PlacesOrganizer = {
let backupDate = PlacesBackups.getDateForFile(backupFiles[i]);
let m = restorePopup.insertBefore(document.createElement("menuitem"),
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("oncommand",
"PlacesOrganizer.onRestoreMenuItemClick(this);");
diff --git a/basilisk/components/places/content/treeView.js b/basilisk/components/places/content/treeView.js
index 810c4ab..dc1f829 100644
--- a/basilisk/components/places/content/treeView.js
+++ b/basilisk/components/places/content/treeView.js
@@ -33,6 +33,15 @@ PlacesTreeView.prototype = {
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),
// Bug 761494:
@@ -495,36 +504,16 @@ PlacesTreeView.prototype = {
let midnight = now - (now % MS_PER_DAY);
midnight += new Date(midnight).getTimezoneOffset() * MS_PER_MINUTE;
- let timeObj = new Date(timeMs);
- return timeMs >= midnight ? this._todayFormatter.format(timeObj)
- : 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 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;
- },
+ let dateFormat = timeMs >= midnight ?
+ Ci.nsIScriptableDateFormat.dateFormatNone :
+ Ci.nsIScriptableDateFormat.dateFormatShort;
- __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;
+ let timeObj = new Date(timeMs);
+ return (this._dateService.FormatDateTime("", dateFormat,
+ Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
+ timeObj.getFullYear(), timeObj.getMonth() + 1,
+ timeObj.getDate(), timeObj.getHours(),
+ timeObj.getMinutes(), timeObj.getSeconds()));
},
COLUMN_TYPE_UNKNOWN: 0,