protected function DateTimePlus::constructFromArray

Creates a date object from an array of date parts.

Converts the input value into an ISO date, forcing a full ISO date even if some values are missing.

1 call to DateTimePlus::constructFromArray()
DateTimePlus::__construct in drupal/core/lib/Drupal/Component/Datetime/DateTimePlus.php
Constructs a date object set to a requested date and timezone.

File

drupal/core/lib/Drupal/Component/Datetime/DateTimePlus.php, line 356
Definition of Drupal\Component\Datetime\DateTimePlus

Class

DateTimePlus
Extends DateTime().

Namespace

Drupal\Component\Datetime

Code

protected function constructFromArray() {
  try {
    parent::__construct('', $this->inputTimeZoneAdjusted);
    $this->inputTimeAdjusted = static::prepareArray($this->inputTimeAdjusted, TRUE);
    if (static::checkArray($this->inputTimeAdjusted)) {

      // Even with validation, we can end up with a value that the
      // parent class won't handle, like a year outside the range
      // of -9999 to 9999, which will pass checkdate() but
      // fail to construct a date object.
      $this->inputTimeAdjusted = static::arrayToISO($this->inputTimeAdjusted);
      parent::__construct($this->inputTimeAdjusted, $this->inputTimeZoneAdjusted);
    }
    else {
      throw new \Exception('The array contains invalid values.');
    }
  } catch (\Exception $e) {
    $this->errors[] = $e
      ->getMessage();
  }
}