Skip to content

Commit

Permalink
Merge pull request #47 from play2lead/same_as_ignore_time
Browse files Browse the repository at this point in the history
Limit date comparison granularity to day (ignore hour, minute, second)
  • Loading branch information
AndrewIngram committed Jul 8, 2015
2 parents 6d778c1 + 7443239 commit aaf57a2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const DateRangePicker = React.createClass({
let start = r.start.startOf('day');
let end = r.end.startOf('day');

if (!dateCursor.isSame(start)) {
if (!dateCursor.isSame(start, 'day')) {
actualStates.push({
state: defaultState,
range: moment.range(
Expand Down Expand Up @@ -311,7 +311,7 @@ const DateRangePicker = React.createClass({
},

statesForRange(range) {
if (range.start.isSame(range.end)) {
if (range.start.isSame(range.end, 'day')) {
return this.statesForDate(range.start);
}
return this.state.dateStates.filter(d => d.get('range').intersect(range)).map(d => d.get('state'));
Expand All @@ -331,7 +331,7 @@ const DateRangePicker = React.createClass({
completeRangeSelection() {
let range = this.state.highlightedRange;

if (range && (!range.start.isSame(range.end) || this.props.singleDateRange)) {
if (range && (!range.start.isSame(range.end, 'day') || this.props.singleDateRange)) {
this.setState({
selectedStartDate: null,
highlightedRange: null,
Expand Down
12 changes: 6 additions & 6 deletions src/calendar/CalendarMonth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ const CalendarMonth = React.createClass({
let isSelectedRangeStart;
let isSelectedRangeEnd;

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

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

return (
<CalendarDate
key={i}
isToday={d.isSame(moment(), 'day')}
isDisabled={!enabledRange.contains(d)}
isHighlightedDate={!!(highlightedDate && highlightedDate.isSame(d))}
isHighlightedRangeStart={!!(highlightedRange && highlightedRange.start.isSame(d))}
isHighlightedRangeEnd={!!(highlightedRange && highlightedRange.end.isSame(d))}
isHighlightedDate={!!(highlightedDate && highlightedDate.isSame(d, 'day'))}
isHighlightedRangeStart={!!(highlightedRange && highlightedRange.start.isSame(d, 'day'))}
isHighlightedRangeEnd={!!(highlightedRange && highlightedRange.end.isSame(d, 'day'))}
isInHighlightedRange={!!(highlightedRange && highlightedRange.contains(d))}
isSelectedDate={isSelectedDate}
isSelectedRangeStart={isSelectedRangeStart}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/areMomentRangesEqual.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function areMomentRangesEqual(r1, r2) {
return r1.start.isSame(r2.start) && r1.end.isSame(r2.end);
return r1.start.isSame(r2.start, 'day') && r1.end.isSame(r2.end, 'day');
}
2 changes: 1 addition & 1 deletion src/utils/shallowEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function shallowEqual(objA, objB) {
moment.isMoment(objA[key]) &&
moment.isMoment(objB[key])
) {
if (!objA[key].isSame(objB[key])) {
if (!objA[key].isSame(objB[key], 'day')) {
return false;
}
} else if (
Expand Down

0 comments on commit aaf57a2

Please sign in to comment.