From 74432394aeaad10870671b521b99000385d5b647 Mon Sep 17 00:00:00 2001 From: Maxim Filimonov Date: Thu, 25 Jun 2015 12:10:17 +1000 Subject: [PATCH] limit date comparsio granularity to day (ignore hour, minute, second) --- src/DateRangePicker.jsx | 6 +++--- src/calendar/CalendarMonth.jsx | 12 ++++++------ src/utils/areMomentRangesEqual.js | 2 +- src/utils/shallowEqual.js | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/DateRangePicker.jsx b/src/DateRangePicker.jsx index 2d77d856..e8d47954 100644 --- a/src/DateRangePicker.jsx +++ b/src/DateRangePicker.jsx @@ -151,7 +151,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( @@ -310,7 +310,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')); @@ -330,7 +330,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, diff --git a/src/calendar/CalendarMonth.jsx b/src/calendar/CalendarMonth.jsx index ade87c0b..5a59012b 100644 --- a/src/calendar/CalendarMonth.jsx +++ b/src/calendar/CalendarMonth.jsx @@ -40,13 +40,13 @@ 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 ( @@ -54,9 +54,9 @@ const CalendarMonth = React.createClass({ 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} diff --git a/src/utils/areMomentRangesEqual.js b/src/utils/areMomentRangesEqual.js index 89ac353c..52ac93ec 100644 --- a/src/utils/areMomentRangesEqual.js +++ b/src/utils/areMomentRangesEqual.js @@ -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'); } diff --git a/src/utils/shallowEqual.js b/src/utils/shallowEqual.js index 745245c0..0f627bde 100644 --- a/src/utils/shallowEqual.js +++ b/src/utils/shallowEqual.js @@ -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 (