You are here

function event_form_date in Event 5

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

Constructs the time select boxes.

Parameters

$timestamp The time GMT timestamp of the event to use as the default: value.

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

$offset timezone offset:

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

File

./event.module, line 1462

Code

function event_form_date($timestamp, $prefix = 'start', $offset) {

  // populate drop down values...
  // ...months
  $months = array(
    1 => t('January'),
    t('February'),
    t('March'),
    t('April'),
    t('May'),
    t('June'),
    t('July'),
    t('August'),
    t('September'),
    t('October'),
    t('November'),
    t('December'),
  );

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

    // ...hours (with leading 0s)
    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;
  }

  // This is a GMT timestamp, so the _event_date() wrapper to display local times.
  $form[$prefix . '_day'] = array(
    '#prefix' => '<div class="container-inline"><div class="day">',
    '#type' => 'textfield',
    '#default_value' => _event_date('d', $timestamp, $offset),
    '#maxlength' => 2,
    '#size' => 2,
    '#required' => TRUE,
  );
  $form[$prefix . '_month'] = array(
    '#type' => 'select',
    '#default_value' => (int) _event_date('n', $timestamp, $offset),
    '#options' => $months,
    '#required' => TRUE,
  );
  $form[$prefix . '_year'] = array(
    '#type' => 'textfield',
    '#default_value' => (int) _event_date('Y', $timestamp, $offset),
    '#maxlength' => 4,
    '#size' => 4,
    '#required' => TRUE,
  );
  $form[$prefix . '_hour'] = array(
    '#prefix' => '</div><div class="time">&#8212;',
    '#type' => 'select',
    '#default_value' => _event_date($hour_format, $timestamp, $offset),
    '#options' => $hours,
    '#required' => TRUE,
  );
  $form[$prefix . '_minute'] = array(
    '#prefix' => ':',
    '#type' => 'select',
    '#default_value' => _event_date('i', $timestamp, $offset),
    '#options' => $minutes,
    '#required' => TRUE,
  );
  if (isset($am_pms)) {
    $form[$prefix . '_ampm'] = array(
      '#type' => 'radios',
      '#default_value' => _event_date('a', $timestamp, $offset),
      '#options' => $am_pms,
      '#required' => TRUE,
    );
  }
  $form[$prefix . '_close'] = array(
    '#type' => 'markup',
    '#value' => '</div></div>',
  );
  return $form;
}