3 namespace Drupal\Core\TypedData\Plugin\DataType;
5 use Drupal\Core\Datetime\DrupalDateTime;
6 use Drupal\Core\TypedData\Type\DateTimeInterface;
9 * A data type for ISO 8601 date strings.
11 * The plain value of this data type is a date string in ISO 8601 format.
14 * id = "datetime_iso8601",
15 * label = @Translation("Date")
18 class DateTimeIso8601 extends StringData implements DateTimeInterface {
23 public function getDateTime() {
25 if (is_array($this->value)) {
26 $datetime = DrupalDateTime::createFromArray($this->value);
29 $datetime = new DrupalDateTime($this->value);
38 public function setDateTime(DrupalDateTime $dateTime, $notify = TRUE) {
39 $this->value = $dateTime->format('c');
40 // Notify the parent of any changes.
41 if ($notify && isset($this->parent)) {
42 $this->parent->onChange($this->name);