Bug 1752130 - Use the current locale instead of the system locale when formatting dates/times. r=mkmelin
Differential Revision: https://phabricator.services.mozilla.com/D137814 --HG-- extra : rebase_source : 9da5b1a2d76a1e3a7c4ea15839e9341ced246246
This commit is contained in:
Родитель
a11082092a
Коммит
94a2eb53c1
|
@ -157,8 +157,7 @@
|
|||
this.setAttribute("day", aDate.day);
|
||||
|
||||
if (this.mShowMonthLabel) {
|
||||
let monthName = cal.l10n.getDateFmtString(`month.${aDate.month + 1}.Mmm`);
|
||||
this.setAttribute("value", aDate.day + " " + monthName);
|
||||
this.setAttribute("value", cal.dtz.formatter.formatDateWithoutYear(this.mDate));
|
||||
} else {
|
||||
this.setAttribute("value", aDate.day);
|
||||
}
|
||||
|
|
|
@ -505,10 +505,14 @@
|
|||
try {
|
||||
dayList[i] = cal.l10n.getDateFmtString(`day.${tempDate.getDay() + 1}.short`);
|
||||
} catch (e) {
|
||||
dayList[i] = tempDate.toLocaleDateString(undefined, { weekday: "short" });
|
||||
dayList[i] = tempDate.toLocaleDateString(Services.locale.appLocalesAsBCP47, {
|
||||
weekday: "short",
|
||||
});
|
||||
useOSFormat = true;
|
||||
}
|
||||
longDayList[i] = tempDate.toLocaleDateString(undefined, { weekday: "long" });
|
||||
longDayList[i] = tempDate.toLocaleDateString(Services.locale.appLocalesAsBCP47, {
|
||||
weekday: "long",
|
||||
});
|
||||
tempDate.setDate(tempDate.getDate() + 1);
|
||||
}
|
||||
|
||||
|
@ -683,7 +687,10 @@
|
|||
}
|
||||
|
||||
if (aDate.getMonth() == date.getMonth() && aDate.getFullYear() == date.getFullYear()) {
|
||||
day.setAttribute("aria-label", date.toLocaleDateString(undefined, { day: "numeric" }));
|
||||
day.setAttribute(
|
||||
"aria-label",
|
||||
date.toLocaleDateString(Services.locale.appLocalesAsBCP47, { day: "numeric" })
|
||||
);
|
||||
} else {
|
||||
day.setAttribute("aria-label", this.dateFormatter.format(date));
|
||||
}
|
||||
|
@ -1003,7 +1010,7 @@
|
|||
XPCOMUtils.defineLazyGetter(
|
||||
CalendarMinimonth.prototype,
|
||||
"dateFormatter",
|
||||
() => new Services.intl.DateTimeFormat(undefined, { dateStyle: "long" })
|
||||
() => new Services.intl.DateTimeFormat(Services.locale.appLocalesAsBCP47, { dateStyle: "long" })
|
||||
);
|
||||
|
||||
MozXULElement.implementCustomInterface(CalendarMinimonth, [
|
||||
|
|
|
@ -9,7 +9,11 @@
|
|||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
|
||||
|
||||
let formatter = new Services.intl.DateTimeFormat(undefined, { timeStyle: "short" });
|
||||
// Leave these first arguments as `undefined`, to use the OS style if
|
||||
// intl.regional_prefs.use_os_locales is true or the app language matches the OS language.
|
||||
// Otherwise, the app language is used.
|
||||
let dateFormatter = new Services.intl.DateTimeFormat(undefined, { dateStyle: "short" });
|
||||
let timeFormatter = new Services.intl.DateTimeFormat(undefined, { timeStyle: "short" });
|
||||
|
||||
let probeSucceeded;
|
||||
let alphaMonths;
|
||||
|
@ -901,8 +905,8 @@
|
|||
// 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 = formatter.format(amTime);
|
||||
pmTime = formatter.format(pmTime);
|
||||
amTime = timeFormatter.format(amTime);
|
||||
pmTime = timeFormatter.format(pmTime);
|
||||
let amLabel = parseTimeRegExp.exec(amTime)[ampmIndex] || "AM";
|
||||
let pmLabel = parseTimeRegExp.exec(pmTime)[ampmIndex] || "PM";
|
||||
|
||||
|
@ -1424,8 +1428,8 @@
|
|||
POST_INDEX = 8;
|
||||
let amProbeTime = new Date(2000, 0, 1, 6, 12, 34);
|
||||
let pmProbeTime = new Date(2000, 0, 1, 18, 12, 34);
|
||||
let amProbeString = formatter.format(amProbeTime);
|
||||
let pmProbeString = formatter.format(pmProbeTime);
|
||||
let amProbeString = timeFormatter.format(amProbeTime);
|
||||
let pmProbeString = timeFormatter.format(pmProbeTime);
|
||||
let amFormatExpr = null,
|
||||
pmFormatExpr = null;
|
||||
if (amProbeString != pmProbeString) {
|
||||
|
@ -1510,11 +1514,16 @@
|
|||
function formatDate(aDate, aTimezone) {
|
||||
// Usually, floating is ok here, so no need to pass aTimezone - we just need to pass
|
||||
// it in if we need to make sure formatting happens without a timezone conversion.
|
||||
let timezone = aTimezone || cal.dtz.floating;
|
||||
return cal.dtz.formatter.formatDateShort(cal.dtz.jsDateToDateTime(aDate, timezone));
|
||||
let formatter = aTimezone
|
||||
? new Services.intl.DateTimeFormat(undefined, {
|
||||
dateStyle: "short",
|
||||
timeZone: aTimezone.tzid,
|
||||
})
|
||||
: dateFormatter;
|
||||
return formatter.format(aDate);
|
||||
}
|
||||
|
||||
function formatTime(aValue) {
|
||||
return formatter.format(aValue);
|
||||
return timeFormatter.format(aValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -371,7 +371,10 @@ function inTimezone(aDate, aOptions) {
|
|||
// the locale of the test machine.
|
||||
formatter = new Services.intl.DateTimeFormat("en-US", optionsWithTimezone);
|
||||
} else {
|
||||
formatter = new Services.intl.DateTimeFormat(undefined, optionsWithTimezone);
|
||||
formatter = new Services.intl.DateTimeFormat(
|
||||
Services.locale.appLocalesAsBCP47,
|
||||
optionsWithTimezone
|
||||
);
|
||||
}
|
||||
formatCache.set(cacheKey, formatter);
|
||||
} catch (ex) {
|
||||
|
@ -391,7 +394,7 @@ function inTimezone(aDate, aOptions) {
|
|||
// the locale of the test machine.
|
||||
formatter = new Services.intl.DateTimeFormat("en-US", aOptions);
|
||||
} else {
|
||||
formatter = new Services.intl.DateTimeFormat(undefined, aOptions);
|
||||
formatter = new Services.intl.DateTimeFormat(Services.locale.appLocalesAsBCP47, aOptions);
|
||||
}
|
||||
formatCache.set(cacheKey, formatter);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче