Bug 1363660 - Disable out of range months and years
MozReview-Commit-ID: 3VIwKVteWag
--- 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;
},