Commit e1e3cc81 authored by Kevin Paxman's avatar Kevin Paxman
Browse files

Update date formatter to limit running to Event's date field

parent 54d9e300
......@@ -1425,52 +1425,53 @@ function uw_ct_event_date_formatter_dates_alter(&$dates, $context) {
// Ignore the formatting settings and provide our own.
// Currently requires the field to be set NOT to show the end date, or odd things will happen.
//dsm($dates);
//dsm($context);
$orig_timezone = date_default_timezone_get();
$timezone = $context['item']['timezone'];
$start = $context['item']['value'];
$end = $context['item']['value2'];
//set event timezone so date calculations work as expected
date_default_timezone_set($timezone);
$start_stamp = strtotime($start);
$end_stamp = strtotime($end);
//define the common part of the string - we will always display the start date
$dates['value']['formatted'] = date('l, F j, Y', $start_stamp);
//check for all day event (using the only identifier available - if it starts & ends at midnight it's all day)
if (substr($start, -8) == '00:00:00' && substr($end, -8) == '00:00:00') {
//all day event - display notifier
$dates['value']['formatted'] .= ' (all day)';
} else {
//event with a time - display it
$dates['value']['formatted'] .= ' - ' . date('g:i A', $start_stamp);
//events that don't span a period of time will need the time zone here
//also need time zone if event crosses time change (e.g. EST -> EDT)
if ($start == $end || date('T', $start_stamp) != date('T', $end_stamp)) {
$dates['value']['formatted'] .= ' ' . date('T', $start_stamp);
}
}
//if event spans a period of time, we need to display the end
if ($start != $end) {
$dates['value']['formatted'] .= ' to';
//check if the event ends on the same day it starts
if (substr($start, 0, 10) != substr($end, 0, 10)) {
//if not, display the end date
$dates['value']['formatted'] .= ' '. date('l, F j, Y', $end_stamp);
}
//only do this for event dates
if (isset($context['field']['field_name']) && $context['field']['field_name'] == 'field_event_date') {
$orig_timezone = date_default_timezone_get();
$timezone = $context['item']['timezone'];
$start = $context['item']['value'];
$end = $context['item']['value2'];
//set event timezone so date calculations work as expected
date_default_timezone_set($timezone);
$start_stamp = strtotime($start);
$end_stamp = strtotime($end);
//define the common part of the string - we will always display the start date
$dates['value']['formatted'] = date('l, F j, Y', $start_stamp);
//check for all day event (using the only identifier available - if it starts & ends at midnight it's all day)
if (substr($start, -8) == '00:00:00' && substr($end, -8) == '00:00:00') {
//all day event - display notifier
$dates['value']['formatted'] .= ' (all day)';
} else {
//event with a time - display it
$dates['value']['formatted'] .= ' - ' . date('g:i A', $start_stamp);
//events that don't span a period of time will need the time zone here
//also need time zone if event crosses time change (e.g. EST -> EDT)
if ($start == $end || date('T', $start_stamp) != date('T', $end_stamp)) {
$dates['value']['formatted'] .= ' ' . date('T', $start_stamp);
}
}
//if event spans a period of time, we need to display the end
if ($start != $end) {
$dates['value']['formatted'] .= ' to';
//check if the event ends on the same day it starts
if (substr($start, 0, 10) != substr($end, 0, 10)) {
$dates['value']['formatted'] .= ' -';
//if not, display the end date
$dates['value']['formatted'] .= ' '. date('l, F j, Y', $end_stamp);
}
//event with a time - display it
$dates['value']['formatted'] .= ' ' . date('g:i A T', $end_stamp);
//check for all day event (using the only identifier available - if it starts & ends at midnight it's all day)
if (substr($start, -8) == '00:00:00' && substr($end, -8) == '00:00:00') {
//all day event - display notifier
$dates['value']['formatted'] .= ' (all day)';
} else {
if (substr($start, 0, 10) != substr($end, 0, 10)) {
$dates['value']['formatted'] .= ' -';
}
//event with a time - display it
$dates['value']['formatted'] .= ' ' . date('g:i A T', $end_stamp);
}
}
//restore site timezone
date_default_timezone_set($orig_timezone);
}
//restore site timezone
date_default_timezone_set($orig_timezone);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment