Is it possible to theme Start Time and End Time? I would like to display the date and time in a different format.

Thanks

Comments

thomasmurphy’s picture

subscribing

phil88’s picture

I found a solution for this. I created a node-event.tpl.php and commented out the $content variable. Then I worked with the end time and start time variables included in the $node object directly.

$node->end_time_format
$node->start_time_format

thomasmurphy’s picture

That sounds internesting. Could you post what you had in node-event.tpl.php instead of $content?

phil88’s picture

I have printed out the variables; here are some:
$node->event_start
$node->event_end

This will show you the entire event node object in node-event.tpl.php
print_r($node);

If you have locations module, you can also display the location with
print_r($node->locations[0]);

yas’s picture

subscribing

lonehorseend’s picture

You have to write a template override in your template.php for the theme_event_nodeapi function.

function theme_event_nodeapi($node) {
 $node->start_format = format_date($node->event_start, 'large', '', $node->start_offset);
 $node->end_format = format_date($node->event_end, 'large', '', $node->end_offset); 

(The rest of the function theme_event_nodeapi code)

The reason it says "large" instead of "long" is that in Drupal 5.7 (and possibly other versions), the admin date and time labels do not match the format_date function.

The equavilent is:

Short (admin) -> Small (format_date)
Medium (admin) -> Medium (format_date)
Long (admin) -> Large (format_date).

This bug was reported for Drupal 6rc4 as well - http://drupal.org/node/221006

For all the things you can theme in event, look in the event.theme file in the event module directory.

Slim Pickens’s picture

This has been driving me nuts for a while now.

I tried the method above and it returns Jan 01 1970.

Stripping it back, I've tried all manner of event node variables in this kind of thing:

/**
 * Format an event node for display
 *
 * @param node
 *   The node which needs its dates formatted
 */  
function marinelli_event_nodeapi($node) {

  $output = '<div class="event-nodeapi"><label>'. t('Start: ') .'</label>'. format_date($node->event['start'], 'custom', 'D, M d') .'</div>'."\n";
  return $output;
}

and all I get is the appropriately formatted Jan 01, 1970.

I'm presuming the actual date is being fed in to the theme code from somewhere else. I see that $node->event['start_format'] is actually being declared in the event.module and doesn't seem amenable to theming.

It would be really great to be able to easily cutomise the date display in theme. I'm trying to use this module on a couple of sites and from my perspective, Year is never needed, and for a gig, for eg, I need something like: Fri May 30 - 8.30pm, but it seems difficult to actually get this.

Any other suggestions?

hargobind’s picture

Two things are wrong with your code:
$node->event['start'] needs to be $node->event_start
And as mentioned in the post above, use 'large' for the second perameter.
...and don't forget the offsets.

It would be wise to just copy/paste directly from the post above and just change the date formats like this:

$node->start_format = format_date($node->event_start, 'large', 'D, M d', $node->start_offset);
$node->end_format = format_date($node->event_end, 'large', 'D, M d', $node->end_offset);
lonehorseend’s picture

Also, my code in post 6 is dependent on whatever you have set in the admin panel for your large, medium, and small date formats.

Slim Pickens’s picture

I've revisited this today wondering if anything had changed with the latest D6 event module, and sadly no.

I've added a start date to the theme function in template.php.

The following code works as expected: Days until the event is displayed in the block, and the start date is shown correctly in full - year, month, day, hours, minutes.

function marinelli_event_upcoming_item($node, $types = array()) {
  $output = l($node->title, "node/$node->nid", array('attributes' => array('title' => $node->title)));
  if (count($types) > 1) {
    $output .= '<span class="event-nodetype">('. $node->event['node_type'] .')</span>';
  }
  $output .= '<div class="event-start">('. $node->event_start .')</div>';
  $output .= '<span class="event-timeleft">('. $node->event['timeleft'] .')</span>';
  return $output;
}

When I wrap $node->event_start in any kind of date format the start date is displayed as (Jan 1 1970 - 10:33am). For eg.

function marinelli_event_upcoming_item($node, $types = array()) {
  $output = l($node->title, "node/$node->nid", array('attributes' => array('title' => $node->title)));
  if (count($types) > 1) {
    $output .= '<span class="event-nodetype">('. $node->event['node_type'] .')</span>';
  }
  $output .= '<div class="event-start">('. format_date($node->event_start, 'small', 'M d, Y', $node->start_offset) .')</div>';
  $output .= '<span class="event-timeleft">('. $node->event['timeleft'] .')</span>';
  return $output;
}

Does anyone know why $format_date should change $node->event_start from the correct input time to 1970?

NiklasBr’s picture

I have not succeeded in making this work either so I am subscribing to this issue.

hm2k’s picture

Version: 5.x-1.x-dev » 6.x-2.x-dev
Priority: Normal » Major

I too am having trouble changing the date format from the short to medium, long or otherwise.

Moving priority to major as it has been an open issue for so long.

stevegmag’s picture

I was able to get it working by adding the following to the template.php file in my theme: (Drupal 6.19)

function [theme-name]_event_nodeapi($node) {
  $output = '<div class="event-nodeapi"><div class="'. $node->type. '-start"><label>'. t('Event Date: ') .'</label>'. format_date(strtotime($node->event['start']), "custom","l, F d, Y",0).'</div></div>'."\n";
  if ($node->event['start'] != $node->event['end']) {
    $output .= '<div class="event-nodeapi"><div class="'. $node->type. '-end"><label>'. t('Event End: ') .'</label>'. format_date(strtotime($node->event['end']), "custom","l, F d, Y",0).'</div></div>'."\n";
  }
  return $output;
}
jackfoust’s picture

#13 worked for me, thanks Steve!

jackfoust’s picture

#13 does not support DST. Had to revert those changes =(

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.