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

Fix for the start date of the range to allow it to contain a time. #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions dist/calendar/CalendarMonth.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,23 @@ var CalendarMonth = _reactAddons2['default'].createClass({
var isSelectedRangeStart = undefined;
var isSelectedRangeEnd = undefined;

if (!hideSelection && value && _moment2['default'].isMoment(value) && value.isSame(d, 'day')) {
isSelectedDate = true;
} else if (!hideSelection && value && (0, _utilsIsMomentRange2['default'])(value) && value.contains(d)) {
function checkRange() {
isInSelectedRange = true;

isSelectedRangeStart = value.start.isSame(d, 'day');
isSelectedRangeEnd = value.end.isSame(d, 'day');
}

if (!hideSelection && value && _moment2['default'].isMoment(value) && value.isSame(d, 'day')) {
isSelectedDate = true;
} else if (!hideSelection && value && (0, _utilsIsMomentRange2['default'])(value)) {
if (value.contains(d)) {
checkRange();
} else if (value.start.isSame(d, 'day')) {
checkRange();
}
}

return _reactAddons2['default'].createElement(CalendarDate, _extends({
key: i,
isToday: d.isSame((0, _moment2['default'])(), 'day'),
Expand Down
14 changes: 11 additions & 3 deletions src/calendar/CalendarMonth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,23 @@ const CalendarMonth = React.createClass({
let isSelectedRangeStart;
let isSelectedRangeEnd;

if (!hideSelection && value && moment.isMoment(value) && value.isSame(d, 'day')) {
isSelectedDate = true;
} else if (!hideSelection && value && isMomentRange(value) && value.contains(d)) {
function checkRange() {
isInSelectedRange = true;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that value.contains would return false when d was say midnight august 2nd and value.start was 5 pm august 2nd. This was only an issue for the start date since the end date of midnight would still be within a date range specified for a time later that same day.

isSelectedRangeStart = value.start.isSame(d, 'day');
isSelectedRangeEnd = value.end.isSame(d, 'day');
}

if (!hideSelection && value && moment.isMoment(value) && value.isSame(d, 'day')) {
isSelectedDate = true;
} else if (!hideSelection && value && isMomentRange(value)) {
if (value.contains(d)) {
checkRange();
} else if (value.start.isSame(d, 'day')) {
checkRange();
}
}

return (
<CalendarDate
key={i}
Expand Down