Unsetting 'Event has time' seems to have no effect when viewing the node.

eg I create an event with a start date of 19 Nov 2008 and unselect 'Event has time'

In the calendar view I see my event displayed as I would expect:

tester
(all day)

But when I view the node I see:

Start: 19 Nov 2008 - 17:00

rather than

Start: 19 Nov 2008

Comments

frank ralf’s picture

That is not an event specific problem. Just go to the date/time settings of Drupal and change the "short date format" to your liking (i.e. only date, no time). That's the one event uses for display.

Frank

jdsaward’s picture

I want it so that:

  • a. when I select 'Event has time' the time does display.
  • b. when I unselect 'Event has time' the time does not display.

Possible?

claudiu.cristea’s picture

Unfortunately is a Event specific issue...

Changing the format in the site settings will not help while this is gonna change the date/time format on the entire site...

domesticat’s picture

I disagree with the solution set out in #1. Yes, changing the format of the short time does eradicate the problem, but it's a fix that causes more problems than it solves. It changes the date display format for all events, not just the ones that shouldn't have an end time.

frank ralf’s picture

Sorry for the misunderstanding. Of course that's only a quick hack or workaround.

I found a patch here (but haven't tested it yet): http://www.drupalcenter.de/node/13362

/**
* Format an node for display
*
* @param node
*   The node which needs it's dates formatted
*/ 
function theme_event_nodeapi($node) {
  // if you didn't want to show the Date in the Node, decomment the next line
//  return '';

// Check - display Date with Time
if($node -> event['has_time'])
{
$output = '<div class="event-nodeapi">
<div class="'. $node->type .'-start dtstart" title="'. event_format_date($node->event['start_utc'], 'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('Start: ') .'</label>'. $node->event['start_format'] .'</div></div>'."\n";
}
// Display Date without Time
else
{
$output = '<div class="event-nodeapi">
<div class="'. $node->type .'-start dtstart" title="'. event_format_date($node->event['start_utc'], 'custom', "Y-m-d\T00:00:00\Z") .'"><label>'. t('Start: ') .' </label>'. str_replace('- '.$node->event['start_time_format'], '', $node->event['start_format']) .'</div></div>'."\n";
}

if (!empty($node->event['has_end_date']) && $node->event['start'] != $node->event['end'])
{
// Check - display Date with Time
if($node -> event['has_time'])
{
$output .= '<div class="event-nodeapi">
<div class="'. $node->type .'-end dtend" title="'. event_format_date($node->event['end_utc'], 'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('End: ') .'</label>'. $node->event['end_format'] .'</div></div>'."\n";
}
// Display Date without Time
else
{
$output .= '<div class="event-nodeapi">
<div class="'. $node->type .'-end dtend" title="'. event_format_date($node->event['end_utc'], 'custom', "Y-m-d\T00:00:000\Z") .'"><label>'. t('End: ') .'</label>'. str_replace('- '.$node->event['end_time_format'], '', $node->event['end_format']) .'</div></div>'."\n";

}
}

  if (variable_get('configurable_timezones', 1)) {
    $zone = event_zonelist_by_id($node->event['timezone']);
    $output .= '<div class="event-nodeapi">
    <div class="'. $node->type .'-tz"><label>'. t('Timezone: ') .'</label>'. t($zone['name']) .'</div></div>'."\n";
  }

  return $output;
}

hth
Frank

frank ralf’s picture

Status: Active » Needs review

only changed status

Frank

killes@www.drop.org’s picture

Status: Needs review » Active

I'd like to have a real patch.

jdsaward’s picture

Yes; perfect. Thank you Frank Ralf.

For those coming along later, here is how I activated the fix of #5

1. Copy the code into my theme file - template.php.
2. Alter the function name from 'theme_event_nodeapi' to 'phptemplate_event_nodeapi'.
3. Upload and test. Disappointment - does not work.
4. Clear the cache.
5. Aha. Perfect.

(This theme over-ride is only necessary until the fix finds it's way into the events module code.)

claudiu.cristea’s picture

A "clean" solution can be achieved with the Date API module. Unfortunately this module is contained in the Date (CCK) module.

If the developers of this module will decide to make this module dependent on Date API then something like this can be done:

/**
 * Format an node for display
 *
 * @param node
 *   The node which needs it's dates formatted
 */  
function theme_event_nodeapi($node) {
  $format = variable_get('date_format_short', 'm/d/Y - H:i');
  if (!$node->event['has_time']) {
    $format =  date_limit_format($format, array('year', 'month', 'day'));
  }
  $event_date_start = event_format_date($node->event['start'], 'custom', $format);
  $event_date_end = event_format_date($node->event['end'], 'custom', $format);
  $output = '<div class="event-nodeapi">
    <div class="'. $node->type .'-start dtstart" title="'. event_format_date($node->event['start_utc'], 'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('Start: ') .'</label>'. $event_date_start .'</div></div>'."\n";
  if (!empty($node->event['has_end_date']) && $node->event['start'] != $node->event['end']) {
    $output .= '<div class="event-nodeapi">
    <div class="'. $node->type .'-end dtend" title="'. event_format_date($node->event['end_utc'], 'custom', "Y-m-d\TH:i:s\Z") .'"><label>'. t('End: ') .'</label>'. $event_date_end .'</div></div>'."\n";
  }
  if (variable_get('configurable_timezones', 1)) {
    $zone = event_zonelist_by_id($node->event['timezone']);
    $output .= '<div class="event-nodeapi">
    <div class="'. $node->type .'-tz"><label>'. t('Timezone: ') .'</label>'. t($zone['name']) .'</div></div>'."\n";
  }
  return $output;
}

Anyway... Date API brings a lot of amazing API features on manipulating, calculating and displaying dates, times and periods. I think that adding this module as a dependency to Event is "a must have". Maybe we can convince Date module maintainers to store Date API as a standalone module. There is no reason to spend huge resources on Event module to build the date/time API infrastructure while this is very well handled in Date API. The above code works very well in my box...

To be more "elegant" the formatting must occur in event_nodeapi() by applying the above solution to $node->event['start_format'] and $node->event['end_format'].

killes@www.drop.org’s picture

I'd rather have a patch to fix this bug rather than a lecture about Date API...

claudiu.cristea’s picture

A patch based on the above code means creating first a dependency to Date API. I will provide a patch as soon as you agree to add this module as dependency to Event.

claudiu.cristea’s picture

Status: Active » Needs review
StatusFileSize
new1.71 KB

Here's the patch

claudiu.cristea’s picture

StatusFileSize
new2.04 KB

And to be more consistent... changed also $node->event['start_time_format'] and $node->event['end_time_format'].

domesticat’s picture

Patch didn't apply cleanly for me, but it was simple enough to do it by hand.

I can't speak for the larger implications of the patch, but it solves the problem for me. Thanks for creating it.

killes@www.drop.org’s picture

Status: Needs review » Needs work

Sorry, but I am not going to make event depend on date for just a simple helper function. Please recreate a simple "strip off hour" function for this purpose.

frank ralf’s picture

I strongly agree with the opinion expressed in #9.

Handling date/time (and timezones) is a very complex task and quite error-prone.

Drupal stores and processes date/time data in quite a lot of different formats: Unix Timestamp format for internal processing, Datetime format for storing in the database, strings for human readable output, arrays for anything in between...

That's the reason, that there's a lot of "imploding" and "exploding" (via the respective PHP functions) and other converting going on under the hood of Event module.

I think a cleaner implementation for Event module would be to hand off the complexity of date/time processing to Date API, where it belongs, and concentrate on its main task of managing Event nodes.

killes@www.drop.org’s picture

Status: Needs work » Fixed

This is now fixed, there's now two variables, one for the date (Y-m-d) and one for the time.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.