public static function DateTimePlus::arrayToISO in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Component/Datetime/DateTimePlus.php \Drupal\Component\Datetime\DateTimePlus::arrayToISO()
Creates an ISO date from an array of values.
Parameters
array $array: An array of date values keyed by date part.
bool $force_valid_date: (optional) Whether to force a full date by filling in missing values. Defaults to FALSE.
Return value
string The date as an ISO string.
1 call to DateTimePlus::arrayToISO()
- DateTimePlus::createFromArray in core/
lib/ Drupal/ Component/ Datetime/ DateTimePlus.php - Creates a date object from an array of date parts.
File
- core/
lib/ Drupal/ Component/ Datetime/ DateTimePlus.php, line 540
Class
- DateTimePlus
- Wraps DateTime().
Namespace
Drupal\Component\DatetimeCode
public static function arrayToISO($array, $force_valid_date = FALSE) {
$array = static::prepareArray($array, $force_valid_date);
$input_time = '';
if ($array['year'] !== '') {
$input_time = static::datePad(intval($array['year']), 4);
if ($force_valid_date || $array['month'] !== '') {
$input_time .= '-' . static::datePad(intval($array['month']));
if ($force_valid_date || $array['day'] !== '') {
$input_time .= '-' . static::datePad(intval($array['day']));
}
}
}
if ($array['hour'] !== '') {
$input_time .= $input_time ? 'T' : '';
$input_time .= static::datePad(intval($array['hour']));
if ($force_valid_date || $array['minute'] !== '') {
$input_time .= ':' . static::datePad(intval($array['minute']));
if ($force_valid_date || $array['second'] !== '') {
$input_time .= ':' . static::datePad(intval($array['second']));
}
}
}
return $input_time;
}