You are here

function _create_hours_arr in Office Hours 5

helper function to create hours array. items are saved in 24 hours string format (i.e '18:00').

2 calls to _create_hours_arr()
office_hours_field_settings in ./office_hours.module
implementation of hook_field Handle the parameters for a field.
office_hours_widget in ./office_hours.module
Implementation of hook_widget().

File

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

Code

function _create_hours_arr($field, $limit = TRUE) {
  $fl1 = $field['limitstart'];
  $fl2 = $field['limitend'];
  $gran = $field['granularity'] == 0 ? 60 : $field['granularity'];
  $limst = 0;
  $limend = 23;
  $mins = '00';
  $mine = 60;
  if ($limit === TRUE) {
    if ($fl1 != 'none') {
      list($limst, $mins) = explode(":", $fl1);
    }
    if ($fl2 != 'none') {
      list($limend, $mine) = explode(":", $fl2);
    }
  }
  $ophours['none'] = t('None');
  if ($field['hoursformat'] == 1) {

    //12-hour clock
    foreach (range($limst, $limend) as $i) {
      $mincounter = $i == $limst ? $mins : 0;

      //in the first iteration, start the count according to limst. if not, begin from 0
      for (; $mincounter <= 45; $mincounter = $mincounter + $gran) {
        if (!($i == $limend && $mincounter > $mine)) {

          //last iteration
          $mincounter = $mincounter == 0 ? '00' : $mincounter;

          //preparing the mincounter for use in a string
          $hr = $i . ':' . $mincounter;
          $ophours[$hr] = convert_to_ampm($hr);
        }
      }
    }
  }
  else {

    //24-hour clock
    foreach (range($limst, $limend) as $i) {
      $mincounter = $i == $limst ? $mins : 0;
      for (; $mincounter <= 45; $mincounter = $mincounter + $gran) {
        if (!($i == $limend && $mincounter > $mine)) {
          $mincounter = $mincounter == 0 ? '00' : $mincounter;
          $hr = $i . ':' . $mincounter;
          $ophours[$hr] = $hr;
        }
      }
    }
  }
  return $ophours;
}