diff --git a/packages/datetime/src/common/monthAndYear.ts b/packages/datetime/src/common/monthAndYear.ts index 8ab036f538..9fbd11bd10 100644 --- a/packages/datetime/src/common/monthAndYear.ts +++ b/packages/datetime/src/common/monthAndYear.ts @@ -58,6 +58,10 @@ export class MonthAndYear { public isSame(monthAndYear: MonthAndYear): boolean { return compareMonthAndYear(this, monthAndYear) === 0; } + + public isSameMonth(monthAndYear: MonthAndYear): boolean { + return this.getMonth() === monthAndYear.getMonth(); + } } // returns negative if left < right diff --git a/packages/datetime/src/dateRangePicker.tsx b/packages/datetime/src/dateRangePicker.tsx index 75431fea1f..e609ccdf3e 100644 --- a/packages/datetime/src/dateRangePicker.tsx +++ b/packages/datetime/src/dateRangePicker.tsx @@ -137,10 +137,6 @@ export class DateRangePicker extends AbstractPureComponent { @@ -150,9 +146,8 @@ export class DateRangePicker extends AbstractPureComponent DateUtils.areSameDay(this.state.value[0], day), [`${SELECTED_RANGE_MODIFIER}-end`]: day => DateUtils.areSameDay(this.state.value[1], day), - [HOVERED_RANGE_MODIFIER]: (day: Date) => { - const { hoverValue, value } = this.state; - const [selectedStart, selectedEnd] = value; + [HOVERED_RANGE_MODIFIER]: day => { + const { hoverValue, value: [selectedStart, selectedEnd] } = this.state; if (selectedStart == null && selectedEnd == null) { return false; } @@ -161,14 +156,14 @@ export class DateRangePicker extends AbstractPureComponent { + [`${HOVERED_RANGE_MODIFIER}-start`]: day => { const { hoverValue } = this.state; if (hoverValue == null || hoverValue[0] == null) { return false; } return DateUtils.areSameDay(hoverValue[0], day); }, - [`${HOVERED_RANGE_MODIFIER}-end`]: (day: Date) => { + [`${HOVERED_RANGE_MODIFIER}-end`]: day => { const { hoverValue } = this.state; if (hoverValue == null || hoverValue[1] == null) { return false; @@ -177,33 +172,10 @@ export class DateRangePicker extends AbstractPureComponent { - return ( - - ); - }); + const shortcutElements = shortcuts.map((s, i) => ( + + )); return [ @@ -480,7 +450,7 @@ export class DateRangePicker extends AbstractPureComponent { - const leftView = new MonthAndYear(newDate.getMonth(), newDate.getFullYear()); + const leftView = MonthAndYear.fromDate(newDate); Utils.safeInvoke(this.props.dayPickerProps.onMonthChange, leftView.getFullDate()); this.updateLeftView(leftView); }; private handleRightMonthChange = (newDate: Date) => { - const rightView = new MonthAndYear(newDate.getMonth(), newDate.getFullYear()); + const rightView = MonthAndYear.fromDate(newDate); Utils.safeInvoke(this.props.dayPickerProps.onMonthChange, rightView.getFullDate()); this.updateRightView(rightView); }; @@ -563,8 +533,8 @@ export class DateRangePicker extends AbstractPureComponent