Backup of db before drupal security update
[yaffs-website] / web / core / lib / Drupal / Core / TypedData / Plugin / DataType / DateTimeIso8601.php
1 <?php
2
3 namespace Drupal\Core\TypedData\Plugin\DataType;
4
5 use Drupal\Core\Datetime\DrupalDateTime;
6 use Drupal\Core\TypedData\Type\DateTimeInterface;
7
8 /**
9  * A data type for ISO 8601 date strings.
10  *
11  * The plain value of this data type is a date string in ISO 8601 format.
12  *
13  * @DataType(
14  *   id = "datetime_iso8601",
15  *   label = @Translation("Date")
16  * )
17  */
18 class DateTimeIso8601 extends StringData implements DateTimeInterface {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function getDateTime() {
24     if ($this->value) {
25       if (is_array($this->value)) {
26         $datetime = DrupalDateTime::createFromArray($this->value);
27       }
28       else {
29         $datetime = new DrupalDateTime($this->value);
30       }
31       return $datetime;
32     }
33   }
34
35   /**
36    * {@inheritdoc}
37    */
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);
43     }
44   }
45
46 }