You are here

function event_form_date in Event 5.2

Same name and namespace in other branches
  1. 5 event.module \event_form_date()

Constructs the time select boxes.

Parameters

$date The date string or date array of the event to use as the default value.:

$prefix The value to prepend to the select element names ('start' or: 'end').

Return value

An array of form elements for month, day, year, hour, and minute

Related topics

1 call to event_form_date()
event_form_alter in ./event.module
Implementation of hook_form_alter

File

./event.module, line 1514

Code

function event_form_date($date, $prefix = 'start') {
  $date = is_string($date) ? event_explode_date($date) : $date;

  // populate drop down values...
  // ...months
  $months = _event_months();

  // ...hours
  if (variable_get('event_ampm', '0')) {
    $hour_format = t('g');
    for ($i = 0; $i <= 12; $i++) {
      $hours[$i] = $i < 10 ? "0{$i}" : $i;
    }
    $am_pms = array(
      'am' => t('am'),
      'pm' => t('pm'),
    );
    if ($date['hour'] < 12) {
      $date['ampm'] = 'am';
    }
    else {
      $date['ampm'] = 'pm';
    }
    $date['hour'] = $date['hour'] % 12;
    if ($date['hour'] == 0) {
      $date['hour'] = 12;
    }
  }
  else {
    $hour_format = t('H');
    for ($i = 0; $i <= 23; $i++) {
      $hours[$i] = $i < 10 ? "0{$i}" : $i;
    }
  }

  // ...minutes (with leading 0s)
  for ($i = 0; $i <= 59; $i++) {
    $minutes[$i] = $i < 10 ? "0{$i}" : $i;
  }
  $form[$prefix . '_day'] = array(
    '#prefix' => '<div class="container-inline"><div class="day">',
    '#type' => 'textfield',
    '#default_value' => $date['day'],
    '#maxlength' => 2,
    '#size' => 2,
    '#required' => TRUE,
  );
  $form[$prefix . '_month'] = array(
    '#type' => 'select',
    '#default_value' => $date['month'],
    '#options' => $months,
    '#required' => TRUE,
  );
  $form[$prefix . '_year'] = array(
    '#type' => 'textfield',
    '#default_value' => $date['year'],
    '#maxlength' => 4,
    '#size' => 4,
    '#required' => TRUE,
  );
  $form[$prefix . '_hour'] = array(
    '#prefix' => '</div><div class="time">&#8212;',
    '#type' => 'select',
    '#default_value' => (int) $date['hour'],
    '#options' => $hours,
    '#required' => TRUE,
  );
  $form[$prefix . '_minute'] = array(
    '#prefix' => ':',
    '#type' => 'select',
    '#default_value' => (int) $date['minute'],
    '#options' => $minutes,
    '#required' => TRUE,
  );
  if (isset($am_pms)) {
    $form[$prefix . '_ampm'] = array(
      '#type' => 'radios',
      '#default_value' => $date['ampm'],
      '#options' => $am_pms,
      '#required' => TRUE,
    );
  }
  $form[$prefix . '_close'] = array(
    '#type' => 'markup',
    '#value' => '</div></div>',
  );
  return $form;
}