You are here

function date_sql_handler::complete_date in Date 7

Same name and namespace in other branches
  1. 5.2 date_api_sql.inc \date_sql_handler::complete_date()
  2. 6.2 date_api_sql.inc \date_sql_handler::complete_date()
  3. 6 date_api_sql.inc \date_sql_handler::complete_date()
  4. 7.3 date_api/date_api_sql.inc \date_sql_handler::complete_date()
  5. 7.2 date_api/date_api_sql.inc \date_sql_handler::complete_date()

Create a complete datetime value out of an incomplete array of selected 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' .

1 call to date_sql_handler::complete_date()
date_sql_handler::arg_range in date_api/date_api_sql.inc
Use the parsed values from the ISO argument to determine the min and max date for this period.

File

date_api/date_api_sql.inc, line 584
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;
}