Skip to content

Commit 8bb6589

Browse files
committed
[fixed] properly select time ranges with min/max set
fixes jquense#9
1 parent 5d7a2e8 commit 8bb6589

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/DaySlot.jsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ let DaySlot = React.createClass({
195195
let selector = this._selector = new Selection(()=> findDOMNode(this))
196196

197197
let selectionState = ({ x, y }) => {
198-
let { date, step, min } = this.props;
198+
let { step, min, max } = this.props;
199199
let { top, bottom } = getBoundsForNode(node)
200200

201201
let mins = this._totalMin;
@@ -204,7 +204,7 @@ let DaySlot = React.createClass({
204204

205205
let current = (y - top) / range;
206206

207-
current = snapToSlot(minToDate(mins * current, date), step)
207+
current = snapToSlot(minToDate(mins * current, min), step)
208208

209209
if (!this.state.selecting)
210210
this._initialDateSlot = current
@@ -214,9 +214,8 @@ let DaySlot = React.createClass({
214214
if (dates.eq(initial, current, 'minutes'))
215215
current = dates.add(current, step, 'minutes')
216216

217-
//end = snapToSlot(minToDate(mins * end, date), step)
218-
let start = dates.min(initial, current)
219-
let end = dates.max(initial, current)
217+
let start = dates.max(min, dates.min(initial, current))
218+
let end = dates.min(max, dates.max(initial, current))
220219

221220
return {
222221
selecting: true,
@@ -279,9 +278,11 @@ let DaySlot = React.createClass({
279278

280279

281280
function minToDate(min, date){
282-
var dt = new Date(date);
281+
var dt = new Date(date)
282+
, totalMins = dates.diff(dates.startOf(date, 'day'), date, 'minutes');
283+
283284
dt = dates.hours(dt, 0);
284-
dt = dates.minutes(dt, min);
285+
dt = dates.minutes(dt, totalMins + min);
285286
dt = dates.seconds(dt, 0)
286287
return dates.milliseconds(dt, 0)
287288
}

0 commit comments

Comments
 (0)