You are here

public function DateTimeIso8601::getDateTime in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php \Drupal\Core\TypedData\Plugin\DataType\DateTimeIso8601::getDateTime()
  2. 9 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 23

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;
  }
}