1 date.elements.inc _date_html5_get_form_value($value_orig, $type, $timestep, $timezone_db, $timezone)

Prepare values from database for the widget form.

Parameters

string $value_orig: Original value from database.

string $type: Form API type of the widget.

int $timestep: Step value for the form, 1 or 60.

string $timezone_db: Timezone of the database value.

string $timezone: Actual timezone for output.

Return value

array:

File

core/modules/date/date.elements.inc, line 2066
Date forms and form themes and validation.

Code

function _date_html5_get_form_value($value_orig, $type, $timestep, $timezone_db, $timezone) {
  $needs_conversion = ($timezone_db != $timezone);
  if (is_numeric($value_orig)) {
    $datetime = new DateTime('@' . $value_orig, new DateTimeZone('UTC'));
    $needs_conversion = TRUE;
  }
  else {
    $datetime = new DateTime($value_orig, new DateTimeZone($timezone_db));
  }

  // Adapt timezone offset to local datetime if necessary.
  if ($needs_conversion) {
    $datetime->setTimezone(new DateTimeZone($timezone));
  }

  $value = array(
    'date' => $datetime->format('Y-m-d'),
  );
  if ($type == 'html_datetime') {
    $pattern = ($timestep > 1) ? 'H:i' : 'H:i:s';
    $value['time'] = $datetime->format($pattern);
  }

  return $value;
}