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

karens’s picture

Status: Active » Closed (won't fix)

I'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.

robclay’s picture

Was this 'feature request' added to the v6 calendar module?

robclay’s picture

handsofaten’s picture

Any 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']...

handsofaten’s picture

Ok, 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).

function phptemplate_preprocess_calendar_month_node(&$vars) {
	//if start time = midnight & event lasts 5 hours or less, don't show the event
	//this is a hackish way of not double-listing an event that goes past midnight
	
	$end_time = explode(' ', $vars['node']->calendar_end);
	
	$start_time = explode(' ', $vars['node']->calendar_start);
	
	$diff = (strtotime($end_time[1]) - strtotime($start_time[1]))/3600;
	
	if($start_time[1] != '00:00:00' || $diff > 5){
		template_preprocess_calendar_node($vars);
	}
}
tandersonmd’s picture

hands,

Where does this code go? I tried it in my main template file to no avail.

Thanks.

Thomas

handsofaten’s picture

Yes, 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.