You are here

function convert_to_ampm in Office Hours 5

Helper function for conversion of clock format.

2 calls to convert_to_ampm()
office_hours_field_formatter in ./office_hours.module
implementation of hook_field_formatter Prepare an individual item for viewing in a browser.
_create_hours_arr in ./office_hours.module
helper function to create hours array. items are saved in 24 hours string format (i.e '18:00').

File

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

Code

function convert_to_ampm($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;
}