8c72c859cee9c2d959ee2a0f3ddc374214055bfc
[yaffs-website] / Timestamp.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  * The timestamp data type.
10  *
11  * @DataType(
12  *   id = "timestamp",
13  *   label = @Translation("Timestamp")
14  * )
15  */
16 class Timestamp extends IntegerData implements DateTimeInterface {
17
18   /**
19    * The data value as a UNIX timestamp.
20    *
21    * @var int
22    */
23   protected $value;
24
25   /**
26    * {@inheritdoc}
27    */
28   public function getDateTime() {
29     if ($this->value) {
30       return DrupalDateTime::createFromTimestamp($this->value);
31     }
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function setDateTime(DrupalDateTime $dateTime, $notify = TRUE) {
38     $this->value = $dateTime->getTimestamp();
39     // Notify the parent of any changes.
40     if ($notify && isset($this->parent)) {
41       $this->parent->onChange($this->name);
42     }
43   }
44
45 }