Bug 1346549 - replace nsIScriptableDateFormat in mail/ and mailnews/. r=aceman
--- a/mail/components/activity/content/activity.xml
+++ b/mail/components/activity/content/activity.xml
@@ -232,33 +232,25 @@
anonid).setAttribute('hidden', !visible);
]]>
</body>
</method>
<method name="formatTimeTip">
<parameter name="time"/>
<body>
<![CDATA[
- let dts = Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
- .getService(Components.interfaces.nsIScriptableDateFormat);
+ const dateTimeFormatter = Services.intl.createDateTimeFormat(undefined, {
+ dateStyle: "long", timeStyle: "short"
+ });
// Get the end time to display
let end = new Date(parseInt(time));
// Set the tooltip to be the full date and time
- let dateTimeTip = dts.FormatDateTime("",
- dts.dateFormatLong,
- dts.timeFormatNoSeconds,
- end.getFullYear(),
- end.getMonth() + 1,
- end.getDate(),
- end.getHours(),
- end.getMinutes(),
- 0);
- return dateTimeTip;
+ return dateTimeFormatter.format(end);
]]>
</body>
</method>
</implementation>
</binding>
<binding id="activity-process"
extends="chrome://messenger/content/activity.xml#activity-base">
--- a/mail/components/addrbook/content/abCardViewOverlay.js
+++ b/mail/components/addrbook/content/abCardViewOverlay.js
@@ -273,29 +273,32 @@ function DisplayCardViewPane(realCard)
// Other section
// setup the birthday information
var day = card.getProperty("BirthDay", null);
var month = card.getProperty("BirthMonth", null);
var year = card.getProperty("BirthYear", null);
var dateStr;
if (day > 0 && day < 32 && month > 0 && month < 13) {
var date;
+ var formatter;
if (year) {
// use UTC-based calculations to avoid off-by-one day
// due to time zone/dst discontinuity
date = new Date(Date.UTC(year, month - 1, day));
date.setUTCFullYear(year); // to handle two-digit years properly
- dateStr = date.toLocaleDateString(undefined, {timeZone: "UTC"});
+ formatter = Services.intl.createDateTimeFormat(undefined,
+ { dateStyle: "long", timeZone: "UTC" });
}
// if the year doesn't exist, display Month DD (ex. January 01)
else {
date = new Date(Date.UTC(saneBirthYear(year), month - 1, day));
- dateStr = date.toLocaleDateString(undefined,
- { day: "numeric", month: "long", timeZone: "UTC" });
+ formatter = Services.intl.createDateTimeFormat(undefined,
+ { month: "long", day: "numeric", timeZone: "UTC" });
}
+ dateStr = formatter.format(date);
}
else if (year)
dateStr = year;
visible = cvSetNodeWithLabel(data.cvBirthday, zBirthday, dateStr);
visible = cvSetNodeWithLabel(data.cvCustom1, zCustom1,
card.getProperty("Custom1")) || visible;
visible = cvSetNodeWithLabel(data.cvCustom2, zCustom2,
--- a/mail/components/preferences/cookies.js
+++ b/mail/components/preferences/cookies.js
@@ -4,18 +4,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/PluralForm.jsm");
var nsICookie = Components.interfaces.nsICookie;
var gCookiesWindow = {
- _ds : Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
- .getService(Components.interfaces.nsIScriptableDateFormat),
_hosts : {},
_hostOrder : [],
_tree : null,
_bundle : null,
init: function ()
{
Services.obs.addObserver(this, "cookie-changed", false);
@@ -512,24 +510,20 @@ var gCookiesWindow = {
}
this._view._rowCount = hostCount.value;
},
formatExpiresString: function (aExpires)
{
if (aExpires) {
var date = new Date(1000 * aExpires);
- return this._ds.FormatDateTime("", this._ds.dateFormatLong,
- this._ds.timeFormatSeconds,
- date.getFullYear(),
- date.getMonth() + 1,
- date.getDate(),
- date.getHours(),
- date.getMinutes(),
- date.getSeconds());
+ const dateTimeFormatter = Services.intl.createDateTimeFormat(undefined, {
+ dateStyle: "long", timeStyle: "long"
+ });
+ return dateTimeFormatter.format(date);
}
return this._bundle.getString("expireAtEndOfSession");
},
_getUserContextString: function(aUserContextId) {
// Thunderbird ignores the context for now.
return this._bundle.getString("defaultUserContextLabel");
},
--- a/mailnews/base/content/dateFormat.js
+++ b/mailnews/base/content/dateFormat.js
@@ -17,23 +17,20 @@ var gSearchDateLeadingZeros;
function initLocaleShortDateFormat()
{
// default to mm/dd/yyyy
gSearchDateFormat = 3;
gSearchDateSeparator = "/";
gSearchDateLeadingZeros = true;
try {
- var dateFormatService = Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
- .getService(Components.interfaces.nsIScriptableDateFormat);
- var dateString = dateFormatService.FormatDate("",
- dateFormatService.dateFormatShort,
- 1999,
- 12,
- 1);
+ const dateFormatter = Services.intl.createDateTimeFormat(undefined,
+ { dateStyle: "short" });
+ var aDate = new Date(1999, 11, 1);
+ var dateString = dateFormatter.format(aDate);
// find out the separator
var possibleSeparators = "/-.";
var arrayOfStrings;
for ( var i = 0; i < possibleSeparators.length; ++i )
{
arrayOfStrings = dateString.split( possibleSeparators[i] );
if ( arrayOfStrings.length == 3 )
--- a/mailnews/base/util/templateUtils.js
+++ b/mailnews/base/util/templateUtils.js
@@ -5,16 +5,17 @@
var EXPORTED_SYMBOLS = ["PluralStringFormatter", "makeFriendlyDateAgo"];
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var Cu = Components.utils;
Cu.import("resource://gre/modules/PluralForm.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource:///modules/StringBundle.js");
function PluralStringFormatter(aBundleURI) {
this._bundle = new StringBundle(aBundleURI);
}
PluralStringFormatter.prototype = {
get: function(aStringName, aReplacements, aPluralCount) {
@@ -29,59 +30,62 @@ PluralStringFormatter.prototype = {
},
};
var gTemplateUtilsStrings = new PluralStringFormatter(
"chrome://messenger/locale/templateUtils.properties"
);
+const _dateFormatter = Services.intl.createDateTimeFormat(undefined,
+ { dateStyle: "short" });
+const _dayMonthFormatter = Services.intl.createDateTimeFormat(undefined,
+ { month: "long", day: "numeric" });
+const _timeFormatter = Services.intl.createDateTimeFormat(undefined,
+ { timeStyle: "short" });
+const _weekdayFormatter = Services.intl.createDateTimeFormat(undefined,
+ { weekday: "long" });
+
/**
* Helper function to generate a localized "friendly" representation of
* time relative to the present. If the time input is "today", it returns
* a string corresponding to just the time. If it's yesterday, it returns
* "yesterday" (localized). If it's in the last week, it returns the day
* of the week. If it's before that, it returns the date.
*
* @param time {Date}
* the time (better be in the past!)
* @return {string} A "human-friendly" representation of that time
* relative to now.
*/
function makeFriendlyDateAgo(time)
{
- let dts = Cc["@mozilla.org/intl/scriptabledateformat;1"]
- .getService(Ci.nsIScriptableDateFormat);
-
// Figure out when today begins
let now = new Date();
let today = new Date(now.getFullYear(), now.getMonth(),
now.getDate());
// Get the end time to display
let end = time;
// Figure out if the end time is from today, yesterday,
// this week, etc.
let dateTime;
let kDayInMsecs = 24 * 60 * 60 * 1000;
let k6DaysInMsecs = 6 * kDayInMsecs;
if (end >= today) {
// activity finished after today started, show the time
- dateTime = dts.FormatTime("", dts.timeFormatNoSeconds,
- end.getHours(), end.getMinutes(),0);
+ dateTime = _timeFormatter.format(end);
} else if (today - end < kDayInMsecs) {
// activity finished after yesterday started, show yesterday
dateTime = gTemplateUtilsStrings.get("yesterday");
} else if (today - end < k6DaysInMsecs) {
// activity finished after last week started, show day of week
- dateTime = end.toLocaleDateString(undefined, { weekday: "long" });;
+ dateTime = _weekdayFormatter.format(end);
} else if (now.getFullYear() == end.getFullYear()) {
// activity must have been from some time ago.. show month/day
- dateTime = end.toLocaleDateString(undefined, { day: "numeric", month: "long" });
+ dateTime = _dayMonthFormatter.format(end);
} else {
// not this year, so show full date format
- dateTime = dts.FormatDate("", dts.dateFormatShort,
- end.getFullYear(), end.getMonth() + 1,
- end.getDate());
+ dateTime = _dateFormatter.format(end);
}
return dateTime;
}