Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use moment-range overlaps method #155

Merged
merged 2 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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