function date_default_value_part

cis7 date_elements.inc date_default_value_part($item, $field, $instance, $langcode, $part = 'value')
cle7 date_elements.inc date_default_value_part($item, $field, $instance, $langcode, $part = 'value')
elmsmedia7 date_elements.inc date_default_value_part($item, $field, $instance, $langcode, $part = 'value')
icor7 date_elements.inc date_default_value_part($item, $field, $instance, $langcode, $part = 'value')
meedjum_blog7 date_elements.inc date_default_value_part($item, $field, $instance, $langcode, $part = 'value')
mooc7 date_elements.inc date_default_value_part($item, $field, $instance, $langcode, $part = 'value')

Helper function for the date default value callback to set either 'value' or 'value2' to its default value.

1 call to date_default_value_part()
date_default_value in sites/all/modules/ulmus/date/date_elements.inc
The callback for setting a default value for an empty date field.

File

sites/all/modules/ulmus/date/date_elements.inc, line 199
Date forms and form themes and validation.

Code

function date_default_value_part($item, $field, $instance, $langcode, $part = 'value') {
  $timezone = date_get_timezone($field['settings']['tz_handling']);
  $timezone_db = date_get_timezone_db($field['settings']['tz_handling']);
  $date = NULL;
  if ($part == 'value') {
    $default_value = $instance['settings']['default_value'];
    $default_value_code = $instance['settings']['default_value_code'];
  }
  else {
    $default_value = $instance['settings']['default_value2'];
    $default_value_code = $instance['settings']['default_value_code2'];
  }
  if (empty($default_value) || $default_value == 'blank') {
    return NULL;
  }
  elseif ($default_value == 'strtotime' && !empty($default_value_code)) {
    $date = new DateObject($default_value_code, date_default_timezone());
  }
  elseif ($part == 'value2' && $default_value == 'same') {
    if ($instance['settings']['default_value'] == 'blank' || empty($item[0]['value'])) {
      return NULL;
    }
    else {
      // The date stored in 'value' has already been switched to the db timezone.
      $date = new DateObject($item[0]['value'], $timezone_db, DATE_FORMAT_DATETIME);
    }
  }
  // Special case for 'now' when using dates with no timezone,
  // make sure 'now' isn't adjusted to UTC value of 'now' .
  elseif ($field['settings']['tz_handling'] == 'none') {
    $date = date_now();
  }
  else {
    $date = date_now($timezone);
  }
  // The default value needs to be in the database timezone.
  date_timezone_set($date, timezone_open($timezone_db));
  $date->limitGranularity($field['settings']['granularity']);
  return $date;
}