protected function DateTimePlus::constructFallback

Creates a date when none of the other methods are appropriate.

Fallback construction for values that don't match any of the other patterns. Lets the parent dateTime attempt to turn this string into a valid date.

1 call to DateTimePlus::constructFallback()
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 433
Definition of Drupal\Component\Datetime\DateTimePlus

Class

DateTimePlus
Extends DateTime().

Namespace

Drupal\Component\Datetime

Code

protected function constructFallback() {
  try {

    // One last test for invalid input before we try to construct
    // a date. If the input contains totally bogus information
    // it will blow up badly if we pass it to the constructor.
    // The date_parse() function will tell us if the input
    // makes sense.
    if (!empty($this->inputTimeAdjusted)) {
      $test = date_parse($this->inputTimeAdjusted);
      if (!empty($test['errors'])) {
        $this->errors[] = $test['errors'];
      }
    }
    if (empty($this->errors)) {
      parent::__construct($this->inputTimeAdjusted, $this->inputTimeZoneAdjusted);
    }
  } catch (\Exception $e) {
    $this->errors[] = $e
      ->getMessage();
  }
}