function DateSqlHandler::complete_date in Date 8
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 DateSqlHandler::complete_date()
- DateSqlHandler::arg_range in date_api/
lib/ Drupal/ date_api/ DateSqlHandler.php - Use the parsed values from the ISO argument to determine the min and max date for this period.
File
- date_api/
lib/ Drupal/ date_api/ DateSqlHandler.php, line 730
Class
- DateSqlHandler
- A class to manipulate date SQL.
Namespace
Drupal\date_apiCode
function complete_date($selected, $type = 'now') {
$calendar = system_calendar();
if (empty($selected)) {
return '';
}
// Special case for weeks.
if (array_key_exists('week', $selected)) {
if (config('date_api.settings')
->get('iso8601')) {
$dates = date_iso_week_range($selected['week'], $selected['year']);
}
else {
$dates = date_calendar_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'] = $calendar
->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;
}