You are here

function template_preprocess_calendar_time_row_heading in Calendar 8

Format the time row headings in the week and day view.

@todo find out if this should be helper function instead of a preprocessor.

2 calls to template_preprocess_calendar_time_row_heading()
template_preprocess_calendar_day in ./calendar.theme.inc
Display a day view.
template_preprocess_calendar_week in ./calendar.theme.inc
Display a week view.

File

./calendar.theme.inc, line 667
Theme functions for the Calendar module.

Code

function template_preprocess_calendar_time_row_heading($vars) {
  $start_time = $vars['start_time'];
  $next_start_time = $vars['next_start_time'];
  $curday_date = $vars['curday_date'];
  static $format_hour, $format_ampm;
  if (empty($format_hour)) {
    $format = DateFormat::load('short')
      ->getPattern();
    if (substr($start_time, -5) == '00:00' && substr($next_start_time, -5) == '00:00') {
      $limit = [
        'hour',
      ];
    }
    else {
      $limit = [
        'hour',
        'minute',
      ];
    }
    $granularities = [
      'year',
      'month',
      'day',
      'hour',
      'minute',
      'second',
      'timezone',
    ];
    $reversedLimit = array_diff($granularities, $limit);
    $format_hour = str_replace([
      'a',
      'A',
    ], '', CalendarHelper::limitFormat($format, $reversedLimit));
    $format_ampm = strstr($format, 'a') ? 'a' : (strstr($format, 'A') ? 'A' : '');
  }
  if ($start_time == '00:00:00' && $next_start_time == '23:59:59') {
    $hour = t('All times');
  }
  elseif ($start_time == '00:00:00') {
    $date = date_create($curday_date . ' ' . $next_start_time);
    $hour = t('Before @time', [
      '@time' => date_format($date, $format_hour),
    ]);
  }
  else {
    $date = date_create($curday_date . ' ' . $start_time);
    $hour = date_format($date, $format_hour);
  }
  if (!empty($date)) {
    $ampm = date_format($date, $format_ampm);
  }
  else {
    $ampm = '';
  }
  return [
    'hour' => $hour,
    'ampm' => $ampm,
  ];
}