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

--HG--
extra : rebase_source : f1b512d36f46e1f77537d2a5371f45dec72b625e
This commit is contained in:
Scott Wu 2017-06-07 20:04:44 -07:00
parent 0da40ec53c
commit 383df7ce58

View File

@ -285,8 +285,11 @@ function DatePicker(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";
@ -312,7 +315,7 @@ function DatePicker(context) {
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)
};