Skip to content

Commit

Permalink
Don't use 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.
  • Loading branch information
chadnickbok committed Sep 6, 2016
1 parent d83f0ce commit fca9585
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,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) && !(monthRange.contains(value.start) || monthRange.contains(value.end))) {
value = null;
}

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

if (!isMomentRange(highlightedRange) || !monthRange.overlaps(highlightedRange)) {
if (!isMomentRange(highlightedRange) || !(monthRange.contains(highlightedRange.start) || monthRange.contains(highlightedRange.end))) {
highlightedRange = null;
}

Expand Down

0 comments on commit fca9585

Please sign in to comment.