function DateTimeIso8601::getDateTime

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php \Drupal\Core\TypedData\Plugin\DataType\DateTimeIso8601::getDateTime()
  2. 8.9.x core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php \Drupal\Core\TypedData\Plugin\DataType\DateTimeIso8601::getDateTime()
  3. 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php \Drupal\Core\TypedData\Plugin\DataType\DateTimeIso8601::getDateTime()

Returns the date time object.

Return value

\Drupal\Core\Datetime\DrupalDateTime|null A date object or NULL if there is no date.

Overrides DateTimeInterface::getDateTime

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php, line 24

Class

DateTimeIso8601
A data type for ISO 8601 date strings.

Namespace

Drupal\Core\TypedData\Plugin\DataType

Code

public function getDateTime() {
  if ($this->value) {
    if (is_array($this->value)) {
      // Data of this type must always be stored in UTC.
      $datetime = DrupalDateTime::createFromArray($this->value, 'UTC');
    }
    else {
      // Data of this type must always be stored in UTC.
      $datetime = new DrupalDateTime($this->value, 'UTC');
    }
    return $datetime;
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.