You are here

function date_timezone_input in Date 5

Timezone input form

$params = an array of values, including timezone_in = the timezone of the date/time value to be processed, default is GMT timezone_out = the timezone to be used when displaying the date, default is date site timezone, if set, or GMT valid timezones are standard timezone ids like US/Central, America/New_York, GMT granularity = an array of date parts to be selected, like array('Y','M','D'), default is M, D, Y Y => year, M => month, D => day, H => hours, N => minutes, S => seconds, T => timezone required = 1 if the field must contain a valid date, default is 1 blank_default = 1 to show an empty date field with blank values, 0 to fill with current date, default is 0 weight = the form weight

1 call to date_timezone_input()
date_widget in ./date.module
Implementation of hook_widget().

File

./date.inc, line 946
Date/time API functions

Code

function date_timezone_input($params) {

  // set the variables
  $required = isset($params['required']) ? $params['required'] : 1;
  $blank_default = isset($params['blank_default']) ? $params['blank_default'] : 0;
  $timezone_in = isset($params['timezone_in']) ? $params['timezone_in'] : (!$blank_default || $params['value'] ? 'GMT' : '');
  $timezone_out = isset($params['timezone_out']) ? $params['timezone_out'] : (!$blank_default || $params['value'] ? date_get_site_timezone() : '');
  $opt_fields = is_array($params['opt_fields']) ? $params['opt_fields'] : array();
  $granularity = is_array($params['granularity']) ? $params['granularity'] : array(
    'M',
    'D',
    'Y',
  );
  $weight = $params['weight'];
  $label = $params['label'] ? $params['label'] . ' ' : '';
  if (in_array('T', $granularity)) {
    $form['timezone'] = array(
      '#title' => $label . t('timezone'),
      '#type' => 'select',
      '#default_value' => $timezone_out ? $timezone_out : (!$blank_default ? 'GMT' : ''),
      '#options' => $required ? date_timezone_options() : array(
        '' => '',
      ) + date_timezone_options(),
      '#required' => $required && !in_array('timezone', $opt_fields) ? $required : 0,
    );
  }
  else {
    $form['timezone'] = array(
      '#type' => 'hidden',
      '#value' => $timezone_out,
    );
  }
  $form['#theme'] = 'date_form_timezone';
  $form['#weight'] = $weight;
  return $form;
}