You are here

function date_ap_style_time_string in AP Style Date 7

Creates formatted time string.

Parameters

string $date_string: A string that can be interpreted by strtotime().

array $settings: Array containing settings set in field display configuration.

Return value

string An AP Style formatted time string.

1 call to date_ap_style_time_string()
date_ap_style_field_formatter_view in ./date_ap_style.module
Implements hook_field_formatter_view().

File

./date_ap_style.module, line 299
Formats dates and times to use "AP" Style.

Code

function date_ap_style_time_string($date_string, $settings) {
  $input_datetime = strtotime($date_string);
  $cap_noon = $settings['cap_noon'];

  // Format am and pm to AP Style abbreviations.
  if (date('a', $input_datetime) == 'am') {
    $modmeridian = 'a.m.';
  }
  else {
    $modmeridian = 'p.m.';
  }

  // Reformat 12:00 and 00:00 to noon and midnight.
  if (date('H:i', $input_datetime) == '00:00') {
    if ($cap_noon == TRUE) {
      $ap_time_string = t('Midnight');
    }
    else {
      $ap_time_string = t('midnight');
    }
  }
  elseif (date('H:i', $input_datetime) == '12:00') {
    if ($cap_noon == TRUE) {
      $ap_time_string = t('Noon');
    }
    else {
      $ap_time_string = t('noon');
    }
  }
  elseif (date('i', $input_datetime) == '00') {
    $ap_time_string = date('g', $input_datetime) . ' ' . $modmeridian;
  }
  else {
    $ap_time_string = date('g:i', $input_datetime) . ' ' . $modmeridian;
  }
  return $ap_time_string;
}