function date_fuzzy_datetime in Date 5.2
Same name and namespace in other branches
- 6.2 date_api.module \date_fuzzy_datetime()
- 6 date_api.module \date_fuzzy_datetime()
Create valid datetime value from incomplete ISO dates or arrays.
6 calls to date_fuzzy_datetime()
- date_convert in ./
date_api.module - Date conversion helper function.
- date_formatter_process in date/
date.module - Helper function for creating formatted date arrays from a formatter.
- date_local_date in date/
date_elements.inc - Create local date object.
- date_make_date in ./
date_api.module - Convert a date of any type or an array of date parts into a valid date object.
- date_select_input_value in ./
date_api_elements.inc - Helper function for extracting a date value out of user input.
File
- ./
date_api.module, line 1075 - This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.
Code
function date_fuzzy_datetime($date) {
// A text ISO date, like MMMM-YY-DD HH:MM:SS
if (!is_array($date)) {
$date = date_iso_array($date);
}
elseif (array_key_exists('date', $date) || array_key_exists('time', $date)) {
$date_part = array_key_exists('date', $date) ? $date['date'] : '';
$time_part = array_key_exists('time', $date) ? $date['time'] : '';
$date = date_iso_array(trim($date_part . ' ' . $time_part));
}
// Otherwise date must in in format:
// array('year' => YYYY, 'month' => MM, 'day' => DD).
if (empty($date['year'])) {
$date['year'] = date('Y');
}
if (empty($date['month'])) {
$date['month'] = 1;
}
if (empty($date['day'])) {
$date['day'] = 1;
}
$value = date_pad($date['year'], 4) . '-' . date_pad($date['month']) . '-' . date_pad($date['day']) . ' ' . date_pad($date['hour']) . ':' . date_pad($date['minute']) . ':' . date_pad($date['second']);
return $value;
}