You are here

function _office_hours_select_validate in Office Hours 7

Validate the hours selector element.

1 string reference to '_office_hours_select_validate'
office_hours_element_info in ./office_hours.module
Implements FAPI hook_element_info().

File

includes/office_hours.elements.inc, line 162
Office hours form elements and their theming and validation.

Code

function _office_hours_select_validate($element, &$form_state) {
  $hours = $element['hours']['#value'];
  $minutes = $element['minutes']['#value'] == 0 ? '00' : $element['minutes']['#value'];
  if ($element['#field_settings']['hoursformat'] == 1) {

    // 12 hrs format with 'a.m.' or 'am'.
    if ($element['ampm']['#value'][0] == 'p' && $hours < 1200) {
      $hours += 1200;
    }
    if ($element['ampm']['#value'][0] == 'a' && $hours == 1200) {
      $hours = '0000';
    }
  }
  if ($hours != '' && $minutes != '') {
    form_set_value($element, _office_hours_time_to_mil($hours + $minutes), $form_state);
  }
  else {
    form_set_value($element, '', $form_state);
  }
  if ($hours < 00 || $hours > 2300) {
    form_error($element, t('Hours should be between 0 and 23.', array(), array(
      'office_hours',
    )));
  }
  if ($minutes < 0 || $minutes > 59) {
    form_error($element, t('Minutes should be between 0 and 59.', array(), array(
      'office_hours',
    )));
  }
}