Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DateTimePlus.php

function DateTimePlus::prepareArray

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.

2 calls to DateTimePlus::prepareArray()
DateTimePlus::arrayToISO in core/lib/Drupal/Component/Datetime/DateTimePlus.php
Creates an ISO date from an array of values.
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 584

Class

DateTimePlus
Wraps DateTime().

Namespace

Drupal\Component\Datetime

Code

public static function prepareArray($array, $force_valid_date = FALSE) {
    if ($force_valid_date) {
        $now = new \DateTime();
        $array += [
            'year' => $now->format('Y'),
            'month' => 1,
            'day' => 1,
            'hour' => 0,
            'minute' => 0,
            'second' => 0,
        ];
    }
    else {
        $array += [
            'year' => '',
            'month' => '',
            'day' => '',
            'hour' => '',
            'minute' => '',
            'second' => '',
        ];
    }
    return $array;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal