| Issue 800: | Specifying a minimum duration for events | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Hello,
in my project, I need to specify a min duration for my events (not depending on the slot duration).
So I changed the code in order to have this functionality.
Maybe it can be interesting for other people :
Adding this function :
function verifEventMinTime(event)
{
if (options.minEventDuration)
{
var duration = event.end.getTime() - event.start.getTime();
if (duration < (options.minEventDuration * 60000))
{
var diff = (options.minEventDuration * 60000) - duration;
event.end.setTime(event.end.getTime() + diff);
if (event.end.getHours() >= options.maxTime && event.end.getMinutes() > 0)
{
// Event end time is after the maxTime parameter.
// We move the start parameter in order to terminate at maxTime
var overrunTime = event.end.getTime();
event.end.setHours(options.maxTime);
event.end.setMinutes(0);
var overrun = overrunTime - event.end.getTime();
event.start.setTime(event.start.getTime() - overrun);
}
}
}
return event;
}
Call this function at the beginning of the normalizeEvent(event) function :
event = verifEventMinTime(event);
If too "small", the event is resized to fit the min duration.
And, for example, for a minEventDuration = 30 min, if we add an event at 9:45pm and the calendar ends at 10pm, the event will be moved at 9:30pm, to fit the min duration.
In this code, I can user maxTime only if it's a number (e.g. 22, but without minutes...)
If I change this code to use correctly maxTime, I will comment this issue.
Feb 13, 2011
hmm cool, if this becomes a common enough feature request, i will include it in a real release. until then, ill close the issue, but people will still be able to search for and reference this thread.
Status:
Done
Aug 13, 2013
Nice plugin! i am trying to implement it, but this error: TypeError: 'undefined' is not a function (evaluating 'event.end.getTime()') the event object is being passed and i can log it to my console from within the function, but i cant get the className of event.end. what am i doing wrong? |
|
| ► Sign in to add a comment |
Here is the new code to keep the maxTime fullCalendar format : function getEndStartDiffIfNotSameDay(start, end) { if (start.getDay() != end.getDay()) { return (end.getTime() - start.getTime()) / 60000; } return 0; } function verifEventMinTime(event) { if (options.minEventDuration) { var duration = event.end.getTime() - event.start.getTime(); if (duration < (options.minEventDuration * 60000)) { var diff = (options.minEventDuration * 60000) - duration; event.end.setTime(event.end.getTime() + diff); // Verify if end time is after the maxTime parameter. // Take into account the fact that the event can end // the day after (so parseTime can not be used) var endMinutesFromStartOfDay; var maxMinutesFromStartOfDay; var daydiff = getEndStartDiffIfNotSameDay(event.start, event.end); if (daydiff) { maxMinutesFromStartOfDay = parseTime(options.maxTime); endMinutesFromStartOfDay = parseTime(event.start) + daydiff; } else { endMinutesFromStartOfDay = parseTime(event.end); maxMinutesFromStartOfDay = parseTime(options.maxTime); } if (endMinutesFromStartOfDay > maxMinutesFromStartOfDay) { // We move the start and end parameters in order to terminate at maxTime overrun = endMinutesFromStartOfDay - maxMinutesFromStartOfDay; event.start.setTime(event.start.getTime() - (overrun * 60000)); event.end.setTime(event.end.getTime() - (overrun * 60000)); } } } return event; } Keep in mind that as we specify event duration, an event can end the day after (or more). So we cannot use only parseTime which returns the minutes from the start of the day.