You are here

function _timestamp_validate in Date 8

Custom validation for the timestamp form element. The date element contains an ISO date created from user input, convert it back to a timestamp.

File

./date.module, line 21
Defines date/time field types.

Code

function _timestamp_validate(&$element, &$form_state) {
  $input_exists = FALSE;
  $input = drupal_array_get_nested_value($form_state['values'], $element['#parents'], $input_exists);
  if ($input_exists) {
    $date = new DrupalDateTime($input['value'], $element['value']['#date_timezone']);
    dsm($date);

    // If this is an all day date, set the time back to midnight before saving it.
    if (!empty($input['all_day'])) {
      $date
        ->setTime(0, 0, 0);
    }
    $date
      ->setTimeZone(timezone_open('UTC'));
    form_set_value($element['value'], $date
      ->getTimestamp(), $form_state);
  }
}