Bug 1363660 - Disable out of range months and years draft
authorScott Wu <scottcwwu@gmail.com>
Thu, 04 May 2017 18:15:14 +0800
changeset 676641 796bc34f97638e6f53f740c3159ab3ed3ed7bb47
parent 676640 d54bb49a08e9d1bdab303bc901062092159927c7
child 734995 99b1f7cf519ab717bfdde30beb7e85675e2fd9ba
push id83560
push userbmo:scwwu@mozilla.com
push dateMon, 09 Oct 2017 06:54:12 +0000
bugs1363660
milestone58.0a1
Bug 1363660 - Disable out of range months and years MozReview-Commit-ID: 3VIwKVteWag
toolkit/content/widgets/datekeeper.js
--- a/toolkit/content/widgets/datekeeper.js
+++ b/toolkit/content/widgets/datekeeper.js
@@ -137,19 +137,21 @@ function DateKeeper(props) {
      *           {Number} value: Month in int
      *           {Boolean} enabled
      *         }
      */
     getMonths() {
       let months = [];
 
       for (let i = 0; i < MONTHS_IN_A_YEAR; i++) {
+        const dateObj = this._newUTCDate(this.year, i);
+        const dateObjNext = this._newUTCDate(this.year, i + 1);
         months.push({
           value: i,
-          enabled: true
+          enabled: this.state.min < dateObjNext && this.state.max >= dateObj,
         });
       }
 
       return months;
     },
 
     /**
      * Generate the array of years
@@ -170,19 +172,21 @@ function DateKeeper(props) {
       // last item range. If not, return the cached result.
       if (!firstItem || !lastItem ||
           currentYear <= firstItem.value + YEAR_BUFFER_SIZE ||
           currentYear >= lastItem.value - YEAR_BUFFER_SIZE) {
         // The year is set in the middle with items on both directions
         for (let i = -(YEAR_VIEW_SIZE / 2); i < YEAR_VIEW_SIZE / 2; i++) {
           const year = currentYear + i;
           if (year >= 1 && year <= MAX_YEAR) {
+            const dateObj = this._newUTCDate(year, 0);
+            const dateObjNext = this._newUTCDate(year + 1, 0);
             years.push({
               value: year,
-              enabled: true
+              enabled: this.state.min < dateObjNext && this.state.max >= dateObj,
             });
           }
         }
         this.state.years = years;
       }
       return this.state.years;
     },