You are here

function _office_hours_convert_to_ampm in Office Hours 6

Same name and namespace in other branches
  1. 6.2 office_hours.module \_office_hours_convert_to_ampm()
  2. 7 office_hours.module \_office_hours_convert_to_ampm()

Helper function for conversion of clock format.

3 calls to _office_hours_convert_to_ampm()
theme_office_hours_formatter_default in ./office_hours.theme.inc
Theme function for 'default' text field formatter.
theme_office_hours_formatter_grouped in ./office_hours.theme.inc
Theme function for 'grouped' text field formatter. johnv 4/4/2012: this function is a partial backport from the D7-formatter options the code is copied, but the options are fixed.
_office_hours_show_ampm in ./office_hours.module

File

./office_hours.module, line 323
Creates a field and widget for inserting working or office hours per day

Code

function _office_hours_convert_to_ampm($hour) {
  if (!strstr($hour, ":")) {
    $hour = _office_hours_mil_to_tf($hour);
  }
  list($hr, $min) = explode(":", $hour);
  if ($hr == '0') {

    // midnight
    $hr = 12;
    $ampm = ' AM';
  }
  elseif ($hr == 12) {

    // noon
    $hr = 12;
    $ampm = ' PM';
  }
  elseif ($hr > 12 && $hr < 24) {

    // a pm time
    $hr = $hr - 12;
    $ampm = ' PM';
  }
  else {
    $ampm = ' AM';
  }
  return $hr . ':' . $min . $ampm;
}