Newer
Older
Alex Pott
committed
<?php
namespace Drupal\Core\TypedData\Plugin\DataType;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\TypedData\Type\DateTimeInterface;
/**
* The timestamp data type.
*
* @DataType(
* id = "timestamp",
* label = @Translation("Timestamp")
Alex Pott
committed
* )
*/
class Timestamp extends IntegerData implements DateTimeInterface {
Alex Pott
committed
/**
* The data value as a UNIX timestamp.
*
Jennifer Hodgdon
committed
* @var int
Alex Pott
committed
*/
protected $value;
/**
* {@inheritdoc}
*/
public function getDateTime() {
if ($this->value) {
catch
committed
return DrupalDateTime::createFromTimestamp($this->value);
Alex Pott
committed
}
}
/**
* {@inheritdoc}
*/
public function setDateTime(DrupalDateTime $dateTime, $notify = TRUE) {
Alex Pott
committed
$this->value = $dateTime->getTimestamp();
// Notify the parent of any changes.
if ($notify && isset($this->parent)) {
$this->parent->onChange($this->name);
}
Alex Pott
committed
}