51
51
$node = $element['#node'];
52
52
$field_name = $element['#field_name'];
53
$context = !empty($node->content) ? $node->content[$field_name]['#context'] : '';
53
$context = !empty($node->content) && !empty($node->content[$field_name]) ? $node->content[$field_name]['#context'] : 'full';
54
54
$type_name = $element['#type_name'];
55
55
$fields = content_fields();
56
56
$field = $fields[$field_name];
100
100
// Update the element with values that might have been altered by
101
101
// date_prepare_node() and figure out which values to display.
102
102
$dates = date_formatter_process($element);
104
103
switch ($options['fromto']['fromto']) {
106
105
$date1 = $dates['value']['formatted'];
132
131
// From and To dates match or there is no To date, display a complete single date.
133
132
elseif ($date1 == $date2 || empty($date2)) {
134
$output .= '<span class="date-display-single">'. $date1 . $timezone .'</span>';
133
$output .= theme('date_display_single', $date1, $timezone);
136
135
// Same day, different times, don't repeat the date but show both From and To times.
137
elseif ($dates['value']['formatted_date'] == $dates['value2']['formatted_date']) {
136
elseif (date_has_time($field['granularity']) && $dates['value']['formatted_date'] == $dates['value2']['formatted_date']) {
138
137
// Replace the original time with the from/to time in the formatted start date.
139
138
// Make sure that parentheses or brackets wrapping the time will be retained in the
142
141
$time1 = preg_replace('([\)\]]$)', '', $time1);
143
142
$time2 = preg_replace('`^([\(\[])`', '', $dates['value2']['formatted_time']);
144
143
$time2 = preg_replace('([\)\]]$)', '', $time2);
145
$time = '<span class="date-display-start">'. $time1 .'</span>'.
146
'<span class="date-display-separator"> – </span>'.
147
'<span class="date-display-end">'. $time2 .'</span>';
144
$time = theme('date_display_range', $time1, $time2);
148
145
$replaced = str_replace($time1, $time, $date1);
149
$output .= '<span class="date-display-single">'. $replaced . $timezone .'</span> ';
146
$output .= theme('date_display_single', $replaced, $timezone);
151
148
// Different days, display both in their entirety.
153
$output .= '<span class="date-display-start">'. $date1 .'</span>'.
154
'<span class="date-display-separator"> – </span>'.
150
$output .= theme('date_display_range', $date1, $date2, $timezone);
156
function theme_date_display_single($date, $timezone = NULL) {
157
return '<span class="date-display-single">'. $date . $timezone .'</span>';
160
function theme_date_display_range($date1, $date2, $timezone = NULL) {
161
return '<span class="date-display-start">'. $date1 .'</span>'.
162
'<span class="date-display-separator"> - </span>' .
155
163
'<span class="date-display-end">'. $date2 . $timezone. '</span>';
172
177
function theme_date_format_interval($element) {
173
178
$node = $element['#node'];
174
179
$field_name = $element['#field_name'];
175
$context = !empty($node->content) ? $node->content[$field_name]['#context'] : '';
180
$context = !empty($node->content) ? $node->content[$field_name]['#context'] : 'full';
176
181
$type_name = $element['#type_name'];
177
182
$fields = content_fields();
178
183
$field = $fields[$field_name];
212
217
return theme('date_time_ago', $dates['value']['local']['object'], $dates['value2']['local']['object']);
215
function theme_date_time_ago($start_date, $end_date) {
216
// Time to compare dates to
217
$now = date_format(date_now(), DATE_FORMAT_DATETIME);
218
$start = date_format($start_date, DATE_FORMAT_DATETIME);
219
$end = date_format($end_date, DATE_FORMAT_DATETIME);
221
// 1) The date is entirely in the future
223
return t('!time from now', array('!time' => date_format_interval($start_date, 2)));
226
elseif ($now > $start && $now <= $end) {
227
//return t('Started !time ago', array('!time' => $dates['value']['interval']));
230
// 3) Date is in the past (format_interval added 'ago' to the value).
232
return date_format_interval($start_date, 2);
237
221
* Theme the human-readable description for a Date Repeat rule.