You are here

Timestamp.php in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php

File

core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php
View source
<?php

/**
 * @file
 * Contains \Drupal\Core\TypedData\Plugin\DataType\Timestamp.
 */
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("String")
 * )
 */
class Timestamp extends IntegerData implements DateTimeInterface {

  /**
   * The data value as a UNIX timestamp.
   *
   * @var integer
   */
  protected $value;

  /**
   * {@inheritdoc}
   */
  public function getDateTime() {
    if ($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

Namesort descending Description
Timestamp The timestamp data type.