Closed (won't fix)
Project:
Calendar
Version:
5.x-1.7
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Nov 2007 at 11:59 UTC
Updated:
14 Aug 2009 at 14:43 UTC
I have a number of events that span midnight (tango people are night owls.) So, I want an event that spans midnight to only appear in one date block in the calendar vew.
Insert this code into your theme's template.php .
NOTE: I use a simple date different to figure out if the event is less than a day. (A more general solution would use sunrise or some time in the morning to determine is an event just spans midnight or is part of a multi-day event.)
function phptemplate_calendar_node_month($node) {
$output = '';
$dateDiff = $node->calendar_end - $node->calendar_start;
$Days = floor($dateDiff/(60*60*24));
$Hours = floor(($dateDiff-($Days*60*60*24))/(60*60));
// $Minutes = floor(($dateDiff-($Days*60*60*24)-($Hours*60*60))/60);
// $Seconds = floor($dateDiff-($Days*60*60*24)-($Hours*60*60)-($Minutes*60));
if ($node->calendar_state == 'end' || $node->calendar_state == 'start' ) {
if (( $Days < 1) && ($Hours <= 12)) {
if ( $node->calendar_state == 'end') {
// Eat the end entry
$node->calendar_state = 'singleday';
$output = theme_calendar_empty_day($node);
} else {
$node->calendar_state = 'singleday';
$output = theme_calendar_node_month($node);
}
}
} else {
$output = theme_calendar_node_month($node);
}
return $output;
}
See a sample at http://www.bayareatango.org/d5/calendar (This site is a work in progress, so it may change.)
Comments
Comment #1
karens commentedI'm not making changes to the 5.1 version. I'm officially recommending you move to the 5.2 version now. If you have problems in that version you can check for existing issues or add new ones. Feature requests are now getting posted to the D6 version to be back-ported to 5.2.
If there are still problems in 5.2, we need to report it there.
Comment #2
robclay commentedWas this 'feature request' added to the v6 calendar module?
Comment #3
robclay commentedRe submitted in v6
http://drupal.org/node/445358
Comment #4
handsofaten commentedAny tips on modifying this code for Calendar 6.x-2.1? From what I can tell, the function is now template_calendar_month_node (instead of template_calendar_node_month), and I'm not seeing "calendar_state" in $vars['node']...
Comment #5
handsofaten commentedOk, here's my attempt to solve this problem for Calendar 6.x-2.1. Basically we are checking to see if an event starts at midnight, which usually means it has carried over from the previous day. (So if your calendar does sometimes have events that start at midnight, this will cause them to disappear --- beware). We use the 'calendar_start' variable to see if it starts at midnight (00:00:00) on the current day. We then check to see if the event goes for more than 5 hours after midnight. This prevents it from hiding events that legitimately span several days. If the event starts at midnight and does not last more than 5 hours, it will not be passed on to the 'template_preprocess_calendar_node' function (and therefore will not be displayed). Otherwise, it will be displayed normally.
This is a really hackish function, but as a quick fix it should work (providing you aren't throwing any midnight - 4 am parties).
Comment #6
tandersonmd commentedhands,
Where does this code go? I tried it in my main template file to no avail.
Thanks.
Thomas
Comment #7
handsofaten commentedYes, I put this in my template.php file. Keep in mind it was written for Drupal 6 and Calendar 2.1 -- it won't work if you are still on Drupal 5. Also, this is specifically for the month view (calendar_month_node), and will not effect other views.