You are here

function date_sql_handler::complete_date in Date 6

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. 7.3 date_api/date_api_sql.inc \date_sql_handler::complete_date()
  4. 7 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_sql.inc
Use the parsed values from the ISO argument to determine the min and max date for this period.

File

./date_api_sql.inc, line 517

Class

date_sql_handler
A class to manipulate date SQL.

Code

function complete_date($selected, $type = 'now') {
  $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('t', mktime(0, 0, 0, $compare['month'], 1, $compare['year']));
  }
  $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;
}