diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js --- a/plugins/calendar/calendar_ui.js +++ b/plugins/calendar/calendar_ui.js @@ -1709,7 +1709,7 @@ eventstart = clone_date(event.start, event.allDay ? 1 : 0).getTime(), // calculate with integers eventend = clone_date(event.end, event.allDay ? 2 : 0).getTime(), duration = eventend - eventstart - (event.allDay ? HOUR_MS : 0), /* make sure we don't cross day borders on DST change */ - sinterval = freebusy_data.interval * 60000, + sinterval = freebusy_data.interval * 60000 / (settings.timeslots || 1), intvlslots = 1, numslots = Math.ceil(duration / sinterval), checkdate, slotend, email, ts, slot, slotdate = new Date(); @@ -1719,7 +1719,7 @@ eventend += sinterval * intvlslots * dir; // iterate through free-busy slots and find candidates - var candidatecount = 0, candidatestart = candidateend = success = false; + var candidatecount = 0, candidatestart = false, success = false; for (slot = dir > 0 ? freebusy_data.start.getTime() : freebusy_data.end.getTime() - sinterval; (dir > 0 && slot < freebusy_data.end.getTime()) || (dir < 0 && slot >= freebusy_data.start.getTime()); slot += sinterval * dir) { @@ -1737,7 +1737,7 @@ // respect workingours setting if (freebusy_ui.workinhoursonly) { if (is_weekend(slotdate) || (freebusy_data.interval <= 60 && !is_workinghour(slotdate))) { // skip off-hours - candidatestart = candidateend = false; + candidatestart = false; candidatecount = 0; continue; } @@ -1748,9 +1748,11 @@ // check freebusy data for all attendees ts = date2timestring(slotdate, freebusy_data.interval > 60); + // @TODO: freebusy_data slots should use sinterval not full hour + ts = ts.replace(/[0-9]{4}$/, '0000'); for (var i=0; i < event_attendees.length; i++) { if (freebusy_ui.attendees[i].role != 'OPT-PARTICIPANT' && (email = freebusy_ui.attendees[i].email) && freebusy_data[email] && freebusy_data[email][ts] > 1) { - candidatestart = candidateend = false; + candidatestart = false; break; } } @@ -1761,22 +1763,15 @@ candidatecount = 0; continue; } + else if (dir < 0) + candidatestart = slot; - // set candidate end to slot end time candidatecount++; - if (dir < 0 && !candidateend) - candidateend = slotend; // if candidate is big enough, this is it! if (candidatecount == numslots) { - if (dir > 0) { - event.start.setTime(candidatestart); - event.end.setTime(candidatestart + duration); - } - else { - event.end.setTime(candidateend); - event.start.setTime(candidateend - duration); - } + event.start.setTime(candidatestart); + event.end.setTime(candidatestart + duration); success = true; break; }