Bug 1350679 - Remove deprecated toLocaleFormat from calendar, use Intl.DateTimeFormat instead. r=MakeMyDay
--- a/calendar/base/src/calTimezoneService.js
+++ b/calendar/base/src/calTimezoneService.js
@@ -566,17 +566,17 @@ function guessSystemTimezone() {
Components.utils.reportError(filepath + ": " + ex);
return "";
}
}
function weekday(icsDate, timezone) {
let calDate = cal.createDateTime(icsDate);
calDate.timezone = timezone;
- return cal.dateTimeToJsDate(calDate).toLocaleFormat("%a");
+ return cal.dateTimeToJsDate(calDate).toLocaleString(undefined, { weekday: "short" });
}
// Try to find a tz that matches OS/JSDate timezone. If no name match,
// will use first of probable timezone(s) with highest score.
let probableTZId = "floating"; // default fallback tz if no tz matches.
let probableTZScore = 0;
let probableTZSource = null;
--- a/calendar/import-export/calOutlookCSVImportExport.js
+++ b/calendar/import-export/calOutlookCSVImportExport.js
@@ -24,26 +24,26 @@ var localeEn = {
valueTrue: "True",
valueFalse: "False",
dateRe: /^(\d+)\/(\d+)\/(\d+)$/,
dateDayIndex: 2,
dateMonthIndex: 1,
dateYearIndex: 3,
- dateFormat: "%m/%d/%y",
+ dateFormat: { year: "2-digit", month: "2-digit", day: "2-digit" },
timeRe: /^(\d+):(\d+):(\d+) (\w+)$/,
timeHourIndex: 1,
timeMinuteIndex: 2,
timeSecondIndex: 3,
timeAmPmIndex: 4,
timeAmString: "AM",
timePmString: "PM",
- timeFormat: "%I:%M:%S %p"
+ timeFormat: { hour: "2-digit", minute: "2-digit", second: "2-digit" }
};
var localeNl = {
headTitle: "Onderwerp",
headStartDate: "Begindatum",
headStartTime: "Begintijd",
headEndDate: "Einddatum",
headEndTime: "Eindtijd",
@@ -58,23 +58,21 @@ var localeNl = {
valueTrue: "Waar",
valueFalse: "Onwaar",
dateRe: /^(\d+)-(\d+)-(\d+)$/,
dateDayIndex: 1,
dateMonthIndex: 2,
dateYearIndex: 3,
- dateFormat: "%d-%m-%y",
timeRe: /^(\d+):(\d+):(\d+)$/,
timeHourIndex: 1,
timeMinuteIndex: 2,
- timeSecondIndex: 3,
- timeFormat: "%H:%M:%S"
+ timeSecondIndex: 3
};
var locales = [localeEn, localeNl];
// Windows line endings, CSV files with LF only can't be read by Outlook.
var exportLineEnding = "\r\n";
// Shared functions
@@ -423,21 +421,24 @@ calOutlookCSVExporter.prototype = {
classDescription: "Calendar Outlook CSV Exporter",
interfaces: calOutlookCSVExporterInterfaces
}),
getFileTypes: getOutlookCsvFileTypes,
exportToStream: function(aStream, aCount, aItems) {
// Helper functions
- function dateString(aDateTime) { return cal.dateTimeToJsDate(aDateTime).toLocaleFormat(localeEn.dateFormat); }
- function timeString(aDateTime) { return cal.dateTimeToJsDate(aDateTime).toLocaleFormat(localeEn.timeFormat); }
+ function dateString(aDateTime) {
+ return cal.dateTimeToJsDate(aDateTime).toLocaleString("en-US", localeEn.dateFormat);
+ }
+ function timeString(aDateTime) {
+ return cal.dateTimeToJsDate(aDateTime).toLocaleString("en-US", localeEn.timeFormat);
+ }
function txtString(aString) { return aString || ""; }
- let str = "";
let headers = [];
// Not using a loop here, since we need to be sure the order here matches
// with the orders the field data is added later on
headers.push(localeEn.headTitle);
headers.push(localeEn.headStartDate);
headers.push(localeEn.headStartTime);
headers.push(localeEn.headEndDate);
headers.push(localeEn.headEndTime);
@@ -445,17 +446,17 @@ calOutlookCSVExporter.prototype = {
headers.push(localeEn.headAlarm);
headers.push(localeEn.headAlarmDate);
headers.push(localeEn.headAlarmTime);
headers.push(localeEn.headCategories);
headers.push(localeEn.headDescription);
headers.push(localeEn.headLocation);
headers.push(localeEn.headPrivate);
headers = headers.map(hdr => '"' + hdr + '"');
- str = headers.join(",");
+ let str = headers.join(",");
str += exportLineEnding;
aStream.write(str, str.length);
for (let item of aItems) {
if (!cal.isEvent(item)) {
// XXX TODO: warn the user (once) that tasks are not supported
// (bug 336175)
continue;
--- a/calendar/resources/content/datetimepickers/datetimepickers.xml
+++ b/calendar/resources/content/datetimepickers/datetimepickers.xml
@@ -558,18 +558,18 @@
this.value = new Date();
}
// Change the grids in the timepicker-grids for 12-hours time format.
if (this.ampmIndex) {
// Find the locale strings for the AM/PM prefix/suffix.
let amTime = new Date(2000, 0, 1, 6, 12, 34);
let pmTime = new Date(2000, 0, 1, 18, 12, 34);
- amTime = amTime.toLocaleFormat(this.kTimeFormatString);
- pmTime = pmTime.toLocaleFormat(this.kTimeFormatString);
+ amTime = amTime.toLocaleString(undefined, this.kTimeFormatObject);
+ pmTime = pmTime.toLocaleString(undefined, this.kTimeFormatObject);
let amLabel = this.parseTimeRegExp.exec(amTime)[this.ampmIndex] || "AM";
let pmLabel = this.parseTimeRegExp.exec(pmTime)[this.ampmIndex] || "PM";
document.getAnonymousElementByAttribute(this, "anonid", "timepickerGrids")
.changeTo12HoursFormat(amLabel, pmLabel);
}
]]></constructor>
@@ -1454,16 +1454,17 @@
inherits="value,onchange">
<resources>
<stylesheet src="chrome://lightning-common/skin/datetimepickers.css"/>
</resources>
<implementation>
<constructor><![CDATA[
Components.utils.import("resource://calendar/modules/calUtils.jsm");
+ this.kTimeFormatObject = { hour: "numeric", minute: "2-digit" };
this.initDateFormat();
this.initTimeFormat();
]]></constructor>
<property name="value"
onget="return this.mValue"
onset="this.update(val, false)"/>
@@ -1774,19 +1775,19 @@
let digitsExpr = "(\\d?\\d)(\\D)?(?:(\\d\\d)(\\D)?(?:(\\d\\d)(\\D)?)?)?";
// any letters or '.': non-digit alphanumeric, period (a.m.), or space (P M)
let anyAmPmExpr = "(?:[^\\d\\W]|[. ])+";
// digitsExpr has 6 captures, so index of first ampmExpr is 1, of last is 8.
let probeTimeRegExp =
new RegExp("^(" + anyAmPmExpr + ")?\\s?" + digitsExpr + "(" + anyAmPmExpr + ")?\\s*$");
const PRE_INDEX = 1, HR_INDEX = 2, MIN_INDEX = 4, SEC_INDEX = 6, POST_INDEX = 8; // eslint-disable-line no-unused-vars
let amProbeTime = new Date(2000, 0, 1, 6, 12, 34);
- let amProbeString = amProbeTime.toLocaleFormat("%X");
+ let amProbeString = amProbeTime.toLocaleTimeString();
let pmProbeTime = new Date(2000, 0, 1, 18, 12, 34);
- let pmProbeString = pmProbeTime.toLocaleFormat("%X");
+ let pmProbeString = pmProbeTime.toLocaleTimeString();
let amFormatExpr = null, pmFormatExpr = null;
if (amProbeString != pmProbeString) {
let amProbeArray = probeTimeRegExp.exec(amProbeString);
let pmProbeArray = probeTimeRegExp.exec(pmProbeString);
if (amProbeArray != null && pmProbeArray != null) {
if (amProbeArray[PRE_INDEX] && pmProbeArray[PRE_INDEX] &&
amProbeArray[PRE_INDEX] != pmProbeArray[PRE_INDEX]) {
this.ampmIndex = PRE_INDEX;
@@ -1853,38 +1854,27 @@
// Must recogize "pm" directly, otherwise in "12:34pm" the "S" pattern
// matches the "p" character so only "m" is matched as ampm suffix.)
//
// digitsExpr has 6 captures, so index of first ampmExpr is 1, of last is 8.
this.parseTimeRegExp =
new RegExp("(" + ampmExpr + ")?\\s?" + digitsExpr + "(" + ampmExpr + ")?\\s*$");
this.amRegExp = new RegExp("^(?:" + amExpr + ")$");
this.pmRegExp = new RegExp("^(?:" + pmExpr + ")$");
- // build time display format that mimics "%x" format without seconds
- let ampmSep = (pmProbeString.includes(" ") ? " " : "");
- if (this.ampmIndex == PRE_INDEX) {
- this.kTimeFormatString = "%p" + ampmSep + "%I:%M";
- } else if (this.ampmIndex == POST_INDEX) {
- this.kTimeFormatString = "%I:%M" + ampmSep + "%p";
- } else {
- this.kTimeFormatString = "%H:%M";
- }
]]></body>
</method>
<method name="formatDate">
<parameter name="aDate"/>
<body><![CDATA[
- let dateFormatter = cal.getDateFormatter();
- return dateFormatter.formatDateShort(cal.jsDateToDateTime(aDate, cal.floating()));
+ return cal.getDateFormatter().formatDateShort(cal.jsDateToDateTime(aDate, cal.floating()));
]]></body>
</method>
<method name="formatTime">
<parameter name="aValue"/>
<body><![CDATA[
- // remove leading zero in hours before colon in xx01:23pmxx
- return aValue.toLocaleFormat(this.kTimeFormatString).replace(/0(\d):/, "$1:");
+ return aValue.toLocaleTimeString(undefined, this.kTimeFormatObject);
]]></body>
</method>
</implementation>
</binding>
</bindings>