Skip to content

Commit

Permalink
Don't rely on moment-range overlaps method
Browse files Browse the repository at this point in the history
The moment-range `overlaps` method doesn't consider ranges which 'touch' on equal start/end moments to be overlapping. This breaks highlighting and selection display across month boundaries.

Instead, explicitly test if the first range contains the start and end days of the second range, as well as checking for overlaps.

Oops again
  • Loading branch information
chadnickbok committed Sep 6, 2016
1 parent d83f0ce commit ea2dc04
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ const DateRangePicker = React.createClass({
});
},

rangesOverlap(rangeA, rangeB) {
if (rangeA.overlaps(rangeB) || rangeA.contains(rangeB.start) || rangeA.contains(rangeB.end)) {
return true;
}
return false;
},

renderCalendar(index) {
let {
bemBlock,
Expand Down Expand Up @@ -452,21 +459,17 @@ const DateRangePicker = React.createClass({
let monthEnd = monthDates.last().last();
let monthRange = moment.range(monthStart, monthEnd);

if (moment.isMoment(value)) {
if (!monthRange.contains(value)) {
value = null;
}
} else if (isMomentRange(value)) {
if (!monthRange.overlaps(value)) {
value = null;
}
if (moment.isMoment(value) && !monthRange.contains(value)) {
value = null;
} else if (isMomentRange(value) && !(this.rangesOverlap(monthRange, value))) {
value = null;
}

if (!moment.isMoment(highlightedDate) || !monthRange.contains(highlightedDate)) {
highlightedDate = null;
}

if (!isMomentRange(highlightedRange) || !monthRange.overlaps(highlightedRange)) {
if (!isMomentRange(highlightedRange) || !(this.rangesOverlap(monthRange, highlightedRange))) {
highlightedRange = null;
}

Expand Down

0 comments on commit ea2dc04

Please sign in to comment.