When I create an all-day event, the node for the event automatically displays a start time of 11:00am and an end time of 11:59am. As an all-day event, there should be no start or end time displayed.

Comments

HorsePunchKid’s picture

Category: bug » feature
Priority: Minor » Normal

This is actually pretty easy to theme by overriding theme_event_nodeapi in your theme's template.php. That said, I agree that the default behavior should probably be more natural. I will probably theme my install to produce something like this, modulo the date/time locale settings:

All-day, one day
<div class="event-nodeapi all-day single-day">
    <div class="event-date" title="2007-05-08">
        <label>Date:</label> 2007-05-08
    </div>
</div>

All-day, multiple days
<div class="event-nodeapi all-day multi-day">
    <div class="event-date-start" title="2007-05-08">
        <label>Start:</label> 2007-05-08
    </div>
    <div class="event-date-end"   title="2007-05-15">
        <label>End:</label>   2007-15-08
    </div>
</div>

Partial day, one day
<div class="event-nodeapi partial-day single-day">
    <div class="event-date" title="2007-05-08">
        <label>Date:</label> 2007-05-08
    </div>
    <div class="event-time-start" title="2007-05-08T09:20:49">
        <label>Start:</label> 09:20:49
    </div>
    <div class="event-time-end" title="2007-05-08T14:47:12">
        <label>End:</label> 14:47:12
    </div>
</div>

Partial day, multiple days
<div class="event-nodeapi partial-day single-day">
    <div class="event-date-start" title="2007-05-08T09:20:49">
        <label>Start:</label> 2007-05-08 09:20:49
    </div>
    <div class="event-date-end" title="2007-05-15T14:47:12">
        <label>End:</label> 2007-05-15 14:47:12
    </div>
</div>

If this would be something others would use, perhaps it would be a valuable feature, and I'd gladly roll a patch.

HorsePunchKid’s picture

Version: 5.x-1.x-dev » 5.x-2.x-dev
HorsePunchKid’s picture

This is what I've come up with, which is working well, except that there's no good way to get just the date in the user-specified format, and that there seem to be some problems in event-5.x-2.x-dev that probably aren't in 5.x-1.x.

Any thoughts?

function <your_theme>_event_nodeapi($node) {
  $start_date = preg_replace('/^(.*) (.*)$/', '\1', $node->event['start']);
  $end_date   = preg_replace('/^(.*) (.*)$/', '\1', $node->event['end']);
  $start_time = preg_replace('/^(.*) (.*)$/', '\2', $node->event['start']);
  $end_time   = preg_replace('/^(.*) (.*)$/', '\2', $node->event['end']);

  // Handle all-day events
  if($start_time=="00:00:00" && $end_time=="23:59:00") {
    // Handle all-day, single-day events
    if($start_date==$end_date) {
      $output = '<div class="event-nodeapi all-day single-day">'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date" title="'. event_format_date($node->event['start'], 'custom', "Y-m-d") .'"><label>'. t('Date:') .'</label> '. event_format_date($node->event['start'], 'custom', "Y-m-d") .'</div>'."\n";
    } else { // Handle all-day, multi-day events
      $output = '<div class="event-nodeapi all-day multi-day">'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date-start" title="'. event_format_date($node->event['start'], 'custom', "Y-m-d") .'"><label>'. t('Start:') .'</label> '. event_format_date($node->event['start'], 'custom', "Y-m-d") .'</div>'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date-end"   title="'. event_format_date($node->event['end'],   'custom', "Y-m-d") .'"><label>'. t('End:') .'</label>   '. event_format_date($node->event['end'],   'custom', "Y-m-d")   .'</div>'."\n";
    }
  } else { // Handle partial-day events
    // Handle partial-day, single-day events
    if($start_date==$end_date) {
      $output = '<div class="event-nodeapi partial-day single-day">'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date"       title="'. event_format_date($node->event['start'], 'custom', "Y-m-d")          .'"><label>'. t('Date:') .'</label>  '. event_format_date($node->event['start'], 'custom', "Y-m-d") .'</div>'."\n";
      $output .= "\t".'<div class="'. $node->type. '-time-start" title="'. event_format_date($node->event['start'], 'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('Start:') .'</label> '. event_format_date($node->event['start'], 'custom', "H:i") .'</div>'."\n";
      $output .= "\t".'<div class="'. $node->type. '-time-end"   title="'. event_format_date($node->event['end'],   'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('End:') .'</label>   '. event_format_date($node->event['end'],   'custom', "H:i")   .'</div>'."\n";
    } else { // Handle partial-day, multi-day events
      $output = '<div class="event-nodeapi partial-day multi-day">'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date-start" title="'. event_format_date($node->event['start'], 'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('Start:') .'</label> '. event_format_date($node->event['start'], 'custom', "Y-m-d H:i") .'</div>'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date-end"   title="'. event_format_date($node->event['end'],   'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('End:') .'</label>   '. event_format_date($node->event['end'],   'custom', "Y-m-d H:i")   .'</div>'."\n";
    }
  }
  if (variable_get('configurable_timezones', 1)) {
    $zone = event_zonelist_by_id($node->event['timezone']);
    $output .= '<div class="'. $node->type. '-tz"><label>'. t('Timezone: ') .'</label>'. t($zone['name']) .'</div>'."\n";
  }
  $output.="</div>";
  return $output;
}

(*sigh* It's so ugly using PHP to generate HTML, ironically.)

HorsePunchKid’s picture

Dig out the dynamite, because those dates need to be exploded! Try this instead:

function <your_theme>_event_nodeapi($node) {
  $start_date = preg_replace('/^(.*) (.*)$/', '\1', $node->event['start']);
  $end_date   = preg_replace('/^(.*) (.*)$/', '\1', $node->event['end']);
  $start_time = preg_replace('/^(.*) (.*)$/', '\2', $node->event['start']);
  $end_time   = preg_replace('/^(.*) (.*)$/', '\2', $node->event['end']);

  // Handle all-day events
  if($start_time=="00:00:00" && $end_time=="23:59:00") {
    // Handle all-day, single-day events
    if($start_date==$end_date) {
      $output = '<div class="event-nodeapi all-day single-day">'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date" title="'. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d") .'"><label>'. t('Date:') .'</label> '. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d") .'</div>'."\n";
    } else { // Handle all-day, multi-day events
      $output = '<div class="event-nodeapi all-day multi-day">'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date-start" title="'. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d") .'"><label>'. t('Start:') .'</label> '. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d") .'</div>'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date-end"   title="'. event_format_date($node->event['end_exploded'],   'custom', "Y-m-d") .'"><label>'. t('End:') .'</label>   '. event_format_date($node->event['end_exploded'],   'custom', "Y-m-d")   .'</div>'."\n";
    }
  } else { // Handle partial-day events
    // Handle partial-day, single-day events
    if($start_date==$end_date) {
      $output = '<div class="event-nodeapi partial-day single-day">'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date"       title="'. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d")          .'"><label>'. t('Date:') .'</label>  '. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d") .'</div>'."\n";
      $output .= "\t".'<div class="'. $node->type. '-time-start" title="'. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('Start:') .'</label> '. event_format_date($node->event['start_exploded'], 'custom', "H:i") .'</div>'."\n";
      $output .= "\t".'<div class="'. $node->type. '-time-end"   title="'. event_format_date($node->event['end_exploded'],   'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('End:') .'</label>   '. event_format_date($node->event['end_exploded'],   'custom', "H:i")   .'</div>'."\n";
    } else { // Handle partial-day, multi-day events
      $output = '<div class="event-nodeapi partial-day multi-day">'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date-start" title="'. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('Start:') .'</label> '. event_format_date($node->event['start_exploded'], 'custom', "Y-m-d H:i") .'</div>'."\n";
      $output .= "\t".'<div class="'. $node->type. '-date-end"   title="'. event_format_date($node->event['end_exploded'],   'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('End:') .'</label>   '. event_format_date($node->event['end_exploded'],   'custom', "Y-m-d H:i")   .'</div>'."\n";
    }
  }
  if (variable_get('configurable_timezones', 1)) {
    $zone = event_zonelist_by_id($node->event['timezone']);
    $output .= '<div class="'. $node->type. '-tz"><label>'. t('Timezone: ') .'</label>'. t($zone['name']) .'</div>'."\n";
  }
  $output.="</div>";
  return $output;
}
spazfox’s picture

Thanks for all your work on this, HorsePunchKid! I figured there was a pretty straightforward theming fix, but I'm such a noob I had no idea how to begin.

When I add your theming function to my template.php file, I get a "Call to undefined function: event_format_date()" error. Any ideas?

HorsePunchKid’s picture

I'm sorry, but it looks like event_format_date() only came about in the latest development version of the module, 5.x-2.x-dev. This won't be perfect by a long shot, but you can try replacing those calls to that function with $node->start_format or $node->end_format. So for example:

event_format_date($node->event['start_exploded'], 'custom', "Y-m-d")

...would become simply:

$node->start_format

Hope that helps!

georgelitos’s picture

quick fix for events that have no time, so it doesnt display in node view
remember to uncheck the box [Event has time] for this fix:

edit event.module around line:2154
version 5.x-2.x-dev

if($node->event['has_time']==FALSE)
  $node->event['start_format'] = event_format_date($node->event['start_exploded'], 'custom', 'd/m/Y');
else
  $node->event['start_format'] = event_format_date($node->event['start_exploded'], 'small');
$node->event['start_time_format'] = event_format_date($node->event['start_exploded'], 'custom', (variable_get('event_ampm', '0') ? 'g:i a' : 'H:i'));
if($node->event['has_time']==FALSE)
  $node->event['end_format'] = event_format_date($node->event['end_exploded'], 'custom', 'd/m/Y');
else
  $node->event['end_format'] = event_format_date($node->event['end_exploded'], 'small');
HorsePunchKid’s picture

I can't see how this got set back to bug/minor, but however it happened, I think it was unintentional. Still a feature request, since I think it would be much easier to theme these things if the markup were improved. I'm not sure this still applies to the current dev version.

idsky’s picture

What is a reliable way to check for all-day in an event? I didn't see it in the $node object (passed to event_nodeapi). Checking for midnight isn't good practise and the system puts in the current hour by default (spazfox's original complaint was that is was showing as 11am for an all-day - we haven't fixed that yet).

I dislike the formatting options - there is no time format option, and drupals date formats sadly give limited choice, so I hardcoded my own. Here's how I format my event dates...
Start: Wed, 20 Feb 2008 at 10am    End: 4:30pm

I put both start and end divs into one event-nodeapi div and make them inline in style.css:

.event-start, .event-end {display:inline;}
.event-start {margin-right:1.2em;}

And in template.php:

 function phptemplate_event_nodeapi($node) {

   $startf=str_replace(':00','',date('D, j M Y \a\t g:ia',$node->event_start));
   $output = '<div class="event-nodeapi"><div class="'. $node->type. '-start"><label>'. t('Start: ') .'</label>'.  $startf .'</div>'."\n";

  if ($node->event_start != $node->event_end) {

//don't show end date if same day.
  	if(date('Ymd',$node->event_start)==date('Ymd',$node->event_end)) {
	  $endf=date('g:ia',$node->event_end);
  	} else {
	  $endf=date('D, j M Y \a\t g:ia',$node->event_end);
  	}
  	$endf=str_replace(':00','',$endf);
  	
    $output .= '<div class="'. $node->type. '-end"><label>'. t('End: ') .'</label>'.  $endf.'</div>'."\n";
  }
  $output.='</div>';
  if (variable_get('configurable_timezones', 1)) {
    include_once(EVENT_PATH .'/event_timezones.inc');
    $zones = event_zonelist();
    $output .= '<div class="event-nodeapi"><div class="'. $node->type. '-tz"><label>'. t('Timezone: ') .'</label>'. $zones[$node->timezone] .'</div></div>'."\n";
  }
  return $output;
}
japerry’s picture

Status: Active » Closed (outdated)

Event for Drupal 8 is unrelated to older versions. If an issue similar to this one exists, please open a new issue with the 8.x branch.