On this page
public static function DateTimePlus::prepareArray
public static DateTimePlus::prepareArray($array, $force_valid_date = FALSE)
Creates a complete array from a possibly incomplete array of date parts.
Parameters
array $array: An array of date values keyed by date part.
bool $force_valid_date: (optional) Whether to force a valid date by filling in missing values with valid values or just to use empty values instead. Defaults to FALSE.
Return value
array A complete array of date parts.
File
- core/lib/Drupal/Component/Datetime/DateTimePlus.php, line 528
Class
- DateTimePlus
- Wraps DateTime().
Namespace
Drupal\Component\DatetimeCode
public static function prepareArray($array, $force_valid_date = FALSE) {
if ($force_valid_date) {
$now = new \DateTime();
$array += array(
'year' => $now->format('Y'),
'month' => 1,
'day' => 1,
'hour' => 0,
'minute' => 0,
'second' => 0,
);
}
else {
$array += array(
'year' => '',
'month' => '',
'day' => '',
'hour' => '',
'minute' => '',
'second' => '',
);
}
return $array;
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Datetime!DateTimePlus.php/function/DateTimePlus::prepareArray/8.1.x