DateTimeIso8601.php in Drupal 10
File
core/lib/Drupal/Core/TypedData/Plugin/DataType/DateTimeIso8601.php
View source
<?php
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\TypedData\Type\DateTimeInterface;
class DateTimeIso8601 extends StringData implements DateTimeInterface {
public function getDateTime() {
if ($this->value) {
if (is_array($this->value)) {
$datetime = DrupalDateTime::createFromArray($this->value, 'UTC');
}
else {
$datetime = new DrupalDateTime($this->value, 'UTC');
}
return $datetime;
}
}
public function setDateTime(DrupalDateTime $dateTime, $notify = TRUE) {
$this->value = $dateTime
->format('c');
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
}