Timestamp.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php
  2. 8.9.x core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php
  3. 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php

Namespace

Drupal\Core\TypedData\Plugin\DataType

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php

View source
<?php

namespace Drupal\Core\TypedData\Plugin\DataType;

use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\Attribute\DataType;
use Drupal\Core\TypedData\Type\DateTimeInterface;

/**
 * The timestamp data type.
 */
class Timestamp extends IntegerData implements DateTimeInterface {
    
    /**
     * The data value as a UNIX timestamp.
     *
     * @var int
     */
    protected $value;
    
    /**
     * {@inheritdoc}
     */
    public function getDateTime() {
        if (isset($this->value)) {
            return DrupalDateTime::createFromTimestamp($this->value);
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function setDateTime(DrupalDateTime $dateTime, $notify = TRUE) {
        $this->value = $dateTime->getTimestamp();
        // Notify the parent of any changes.
        if ($notify && isset($this->parent)) {
            $this->parent
                ->onChange($this->name);
        }
    }

}

Classes

Title Deprecated Summary
Timestamp The timestamp data type.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.