Skip to content

Commit a94c478

Browse files
committed
Support start and end date
1 parent 98593a2 commit a94c478

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

cs_date_formatter.module

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,30 +222,51 @@ function cs_date_formatter_theme($existing, $type, $theme, $path) {
222222
* Custom theme function.
223223
*/
224224
function theme_cs_date_formatter_default($variables) {
225-
$value = _cs_date_formatter_get_timestamp($variables['element']);
226-
// @todo make fallback format configurable?
227-
$fallback = format_date($value, 'html_datetime');
228-
$attributes = array(
229-
'datetime' => $fallback,
230-
'class' => array('cs-date-format'),
231-
'data-cs-timestamp' => $value,
232-
'data-cs-setting-name' => $variables['field']['field_name'],
233-
);
234-
$markup = '<time ' . backdrop_attributes($attributes) . '>' . $fallback . '</time>';
225+
$values = _cs_date_formatter_get_timestamp($variables['element']);
226+
$tags = array();
227+
foreach ($values as $key => $value) {
228+
// @todo make fallback format configurable?
229+
$fallback = format_date($value, 'html_datetime');
230+
$attributes = array(
231+
'datetime' => $fallback,
232+
'class' => array('cs-date-format'),
233+
'data-cs-timestamp' => $value,
234+
'data-cs-setting-name' => $variables['field']['field_name'],
235+
);
236+
$tags[] = '<time ' . backdrop_attributes($attributes) . '>' . $fallback . '</time>';
237+
}
238+
$markup = implode(' - ', $tags);
235239

236240
return $markup;
237241
}
238242

239243
/**
240244
* Custom helper function to convert different date formats to timestamp.
245+
*
246+
* @param array $element
247+
*
248+
* @return array
249+
* Array with start and possibly end as timestamps.
241250
*/
242251
function _cs_date_formatter_get_timestamp($element) {
252+
$values = array();
243253
switch ($element['date_type']) {
244254
case 'datestamp':
245-
return $element['value'];
255+
$values['start'] = $element['value'];
256+
if (isset($element['value2'])) {
257+
$values['end'] = $element['value2'];
258+
}
259+
break;
246260

247261
default:
248262
$date = new BackdropDateTime($element['value'], $element['timezone_db']);
249-
return $date->format('U');
263+
$values['start'] = $date->format('U');
264+
if (isset($element['value2'])) {
265+
$date_end = new BackdropDateTime($element['value2'], $element['timezone_db']);
266+
$values['end'] = $date->format('U');
267+
}
268+
break;
269+
250270
}
271+
return $values;
251272
}

0 commit comments

Comments
 (0)