Bug 1370671 - DateTimeFormat timeZone set to UTC to show correct year-month header for datepicker. r=mconley
The datepicker is showing incorrect year-month header in some time zones, which
is similar to
Bug 1331608. It's now fixed by setting the DateTimeFormat timeZone
to UTC. Also done the same thing to the year display for consistency.
MozReview-Commit-ID: LGghmPfYQ5j
--- a/toolkit/content/widgets/datepicker.js
+++ b/toolkit/content/widgets/datepicker.js
@@ -280,18 +280,21 @@ function DatePicker(context) {
* {Function} setMonth
* {Function} getMonthString
* {Array<String>} datetimeOrders
* }
* @param {DOMElement} context
*/
function MonthYear(options, context) {
const spinnerSize = 5;
- const yearFormat = new Intl.DateTimeFormat(options.locale, { year: "numeric" }).format;
- const dateFormat = new Intl.DateTimeFormat(options.locale, { year: "numeric", month: "long" }).format;
+ const yearFormat = new Intl.DateTimeFormat(options.locale, { year: "numeric",
+ timeZone: "UTC" }).format;
+ const dateFormat = new Intl.DateTimeFormat(options.locale, { year: "numeric",
+ month: "long",
+ timeZone: "UTC" }).format;
const spinnerOrder =
options.datetimeOrders.indexOf("month") < options.datetimeOrders.indexOf("year") ?
"order-month-year" : "order-year-month";
context.monthYearView.classList.add(spinnerOrder);
this.context = context;
this.state = { dateFormat };
@@ -307,17 +310,17 @@ function DatePicker(context) {
viewportSize: spinnerSize
}, context.monthYearView),
year: new Spinner({
id: "spinner-year",
setValue: year => {
this.state.isYearSet = true;
options.setYear(year);
},
- getDisplayString: year => yearFormat(new Date(new Date(0).setFullYear(year))),
+ getDisplayString: year => yearFormat(new Date(new Date(0).setUTCFullYear(year))),
viewportSize: spinnerSize
}, context.monthYearView)
};
this._attachEventListeners();
}
MonthYear.prototype = {