I'm fairly new to Drupal, very new to CCK and Views, and very new to Date. I've searched around and found similar things to this, but not quite this.

I'm trying to use the Datestamp CCK field (with selector drop-downs) to create event nodes. I'd really rather not use the event or calendar modules (they seem a little heavy since I don't need calendar style views, just a simple list will do). I'm 90% of the way there, just that last little bit of theme magic is what I need.

I'm not using multiple values but do have the "To Date" set to optional. The time zone is set to site.

I'd like the possibility to create different time spanning events:
1. Single Day - All Day Events
2. Single Day - Non-All Day Events (i.e. 9:00AM - 10:00AM)
3. Multi-Day - All Day Events

It basically comes down to needing to be able to hide certain information.

For example, if a user wants to create a single day all day event, they simply leave off the end date and set the start time to 00:00. I then need to hide the display of "12:00am" when the node outputs.

If a user wants a single day Non-All Day event, I would like to hide the date when the end time outputs. Rather than output "January 22, 2008 - 12:00pm - January 22, 2008 - 1:30pm" I'd like it to output "January 22, 2008 - 12:00pm - 1:30pm".

I imagine this is fairly simple, it's just a matter of knowing what theme function to call.

Comments

dperdue’s picture

Assigned: Unassigned » dperdue
Status: Active » Fixed

I think I've answered my own question. It has to do with the theme_date_display_combination function. I'll post the completed code here when I get it all figured out.

dperdue’s picture

Status: Closed (fixed) » Fixed

Here's the code I came up with.

The only thing I still don't understand is why I had to use db->timestamp instead of local->timestamp to make it work correctly.

function theme_date_display_combination($field, $dates, $node = NULL) {
if ($node->type == "event") { //only want to apply this new formating to event types
  $date1 = $dates['value']['formatted'];
  $date2 = $dates['value2']['formatted'];
  if (empty($date1) && empty($date2)) {
    return '';
  }
  elseif ($date1 == $date2 || empty($date2)) { //this is an all day, single-day event
    return '<span class="date-display-single">'. date('F j, Y', $dates['value']['object']->db->timestamp) .'</span>';
  }
  elseif (date("Hi",$dates['value']['object']->db->timestamp)=="0000") { //this is an all day, multi-day event
  	return '<span class="date-display-start">'. date('F j', $dates['value']['object']->db->timestamp) .'</span><span class="date-display-separator"> - </span><span class="date-display-end">'.date('F j', $dates['value2']['object']->db->timestamp).'</span>';  }

  else { //here are events with multiple times attached
  	if (date("F j, Y",$dates['value']['object']->db->timestamp) == date("F j, Y",$dates['value2']['object']->db->timestamp)) { //this is a single day, multi-time event
 	  	return '<span class="date-display-start">'. date('F j, Y g:ia', $dates['value']['object']->db->timestamp) .'</span><span class="date-display-separator"> - </span><span class="date-display-end">'. date('g:ia', $dates['value2']['object']->db->timestamp) .'</span>';
  	}
  	else { //multi-day, multi time event
  		return '<span class="date-display-start">'. date('F j, Y g:ia', $dates['value']['object']->db->timestamp) .'</span><span class="date-display-separator"> - </span><span class="date-display-end">'. date('F j, Y g:ia', $dates['value2']['object']->db->timestamp) .'</span>';
  	}
}
}

else { //all other node types still get regular treatment
/*...
default theme_date_display_combination
...*/
}
Anonymous’s picture

Status: Fixed » Closed (fixed)

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

jfall’s picture

Status: Fixed » Closed (fixed)

Thanks a ton for the ideas dperdue. I used them to develop a handbook page for the date field documentation...

It provides a different algorithm that is (perhaps?) a little easier to modify to suit other specific needs, and attempts to preserve the short/med/long date formats set by the admin wherever possible.
http://drupal.org/node/235662

Thanks again for sharing your code.

dperdue’s picture

I stumbled across that handbook page the other day and thought "why didn't I see this before?" Now I know why. Thanks for cleaning up the code and making it a little more adaptable.

jimijamesi’s picture

Issue tags: +Newbie

how would we hide this time info info for the calendar month view??

momper’s picture

i asked there: http://drupal.org/node/235662
is there a solution for 6.x? or is it functional for 6.x?

thanks momper