1 date_sql_handler.inc date_sql_handler::complete_date($selected, $type = 'now')

Create a complete date/time value out of an incomplete array of values.

For example, array('year' => 2008, 'month' => 05) will fill in the day, hour, minute and second with the earliest possible values if type = 'min', the latest possible values if type = 'max', and the current values if type = 'now' .

File

core/modules/date/views/date_sql_handler.inc, line 525
SQL helper for Date API.

Class

date_sql_handler
A class to manipulate date SQL.

Code

function complete_date($selected, $type = 'now') {
  if (empty($selected)) {
    return '';
  }
  // Special case for weeks.
  if (array_key_exists('week', $selected)) {
    $dates = date_week_range($selected['week'], $selected['year']);
    switch ($type) {
      case 'empty_now':
      case 'empty_min':
      case 'min':
        return date_format($dates[0], 'Y-m-d H:i:s');

      case 'empty_max':
      case 'max':
        return date_format($dates[1], 'Y-m-d H:i:s');

      default:
        return '';
    }
  }

  $compare = array_merge($this->part_info('empty_' . $type), $selected);
  // If this is a max date, make sure the last day of
  // the month is the right one for this date.
  if ($type == 'max') {
    $compare['day'] = date_days_in_month($compare['year'], $compare['month']);
  }
  $value = '';
  $separators = $this->part_info('sep');
  foreach ($this->date_parts() as $key => $name) {
    $value .= $separators[$key] . (!empty($selected[$key]) ? $selected[$key] : $compare[$key]);
  }
  return $value;
}