Bug 1370671 - DateTimeFormat timeZone set to UTC to show correct year-month header for datepicker. r=mconley draft
authorScott Wu <scottcwwu@gmail.com>
Wed, 07 Jun 2017 20:04:44 -0700
changeset 590779 18c18a7d5a832bbc6d59b647e9f0a2e36e482ffd
parent 590317 a49112c7a5765802096b3fc298069b9495436107
child 632304 83b298cb5796e8008a50d86d66b51f1d9cf3ac37
push id62827
push userbmo:scwwu@mozilla.com
push dateThu, 08 Jun 2017 03:14:26 +0000
reviewersmconley
bugs1370671, 1331608
milestone55.0a1
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
toolkit/content/widgets/datepicker.js
--- 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 = {