Skip to content

Commit

Permalink
Merge pull request #155 from chadnickbok/master
Browse files Browse the repository at this point in the history
Don't use moment-range overlaps method
  • Loading branch information
AlanFoster authored Apr 26, 2018
2 parents ee98e52 + f0e058a commit d657e4d
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -446,6 +446,13 @@ const DateRangePicker = 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 @@ -477,21 +484,17 @@ const DateRangePicker = 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
12 changes: 12 additions & 0 deletions src/tests/DateRangePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ describe('The DateRangePicker component', function () {
expect(calendarMonthComponent.props.highlightedRange).toBe(highlightedRange);
});

it('is set to highlightedRange on month boundaries', function () {
var highlightedRange = moment.range(moment('2016 07 31', 'YYYY MM DD'), moment('2016 08 01', 'YYYY MM DD'));
this.useDocumentRenderer({
firstOfWeek: 1,
initialYear: 2016,
initialMonth: 6,
});
this.renderedComponent.highlightRange(highlightedRange);
var calendarMonthComponent = TestUtils.scryRenderedComponentsWithType(this.renderedComponent, CalendarMonth)[0];
expect(calendarMonthComponent.props.highlightedRange).toBe(highlightedRange);
});

});

describe('each component takes in a large number of other attributes', function () {
Expand Down

0 comments on commit d657e4d

Please sign in to comment.