diff --git a/theme/theme.inc b/theme/theme.inc index 82fb5fb..f878041 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -283,7 +283,24 @@ function template_preprocess_calendar_day(&$vars) { if (!empty($group_time) && !empty($divisor)) { $start_minute = intval(substr($start_time, 3, 2)); $offset = round((date_format($item->date_start, 'i') - $start_minute) / $divisor); - $duration = round(($item->date_end->format('U') - $item->date_start->format('U')) / 60 / $divisor); + + // Get the start and end datetime of the calendar view + $calendar_start_date = new DateTime($view->date_info->date_range[0]->originalTime); + $calendar_end_date = new DateTime($view->date_info->date_range[1]->originalTime); + + // Save the start and end date of the node in two working variables + $event_start = $item->date_start; + $event_end = $item->date_end; + + // Put the time to the limits (00:00:00 and 23:59:59) if the event is not in the actual day + if (date_format($event_start, 'd') < date_format($calendar_start_date, 'd')) { + $event_start = $calendar_start_date; + } + if (date_format($event_end, 'd') > date_format($calendar_end_date, 'd')) { + $event_end = $calendar_end_date; + } + + $duration = round(($event_end->format('U') - $event_start->format('U')) / 60 / $divisor); $item->class = 'd_' . $duration . ' o_' . $offset . ' i_' . $item->indent . ' md_' . min($item->max_depth, 5); } }