From 8bb6589ae07ee7c34568e21b8e53ab3ba47c6d8e Mon Sep 17 00:00:00 2001 From: jquense Date: Sat, 28 Nov 2015 18:59:57 -0500 Subject: [PATCH] [fixed] properly select time ranges with min/max set fixes #9 --- src/DaySlot.jsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/DaySlot.jsx b/src/DaySlot.jsx index 6ea857e98..58b79717a 100644 --- a/src/DaySlot.jsx +++ b/src/DaySlot.jsx @@ -195,7 +195,7 @@ let DaySlot = React.createClass({ let selector = this._selector = new Selection(()=> findDOMNode(this)) let selectionState = ({ x, y }) => { - let { date, step, min } = this.props; + let { step, min, max } = this.props; let { top, bottom } = getBoundsForNode(node) let mins = this._totalMin; @@ -204,7 +204,7 @@ let DaySlot = React.createClass({ let current = (y - top) / range; - current = snapToSlot(minToDate(mins * current, date), step) + current = snapToSlot(minToDate(mins * current, min), step) if (!this.state.selecting) this._initialDateSlot = current @@ -214,9 +214,8 @@ let DaySlot = React.createClass({ if (dates.eq(initial, current, 'minutes')) current = dates.add(current, step, 'minutes') - //end = snapToSlot(minToDate(mins * end, date), step) - let start = dates.min(initial, current) - let end = dates.max(initial, current) + let start = dates.max(min, dates.min(initial, current)) + let end = dates.min(max, dates.max(initial, current)) return { selecting: true, @@ -279,9 +278,11 @@ let DaySlot = React.createClass({ function minToDate(min, date){ - var dt = new Date(date); + var dt = new Date(date) + , totalMins = dates.diff(dates.startOf(date, 'day'), date, 'minutes'); + dt = dates.hours(dt, 0); - dt = dates.minutes(dt, min); + dt = dates.minutes(dt, totalMins + min); dt = dates.seconds(dt, 0) return dates.milliseconds(dt, 0) }