summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php
diff options
context:
space:
mode:
authorAlex Pott2013-06-30 11:03:43 +0100
committerAlex Pott2013-06-30 11:03:43 +0100
commit2e9c7fefd66f563df875a50c44f2807357b69998 (patch)
tree690d897994a49d853baaf17ea7adfe214e34fe9d /core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php
parentc56cb204536ac6ad8fac052d2fabb5b8cec4829e (diff)
Issue #2002102 by Berdir, fago, dixon_: Move TypedData primitive types to interfaces.
Diffstat (limited to 'core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php')
-rw-r--r--core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php
new file mode 100644
index 0000000..18c99dc
--- /dev/null
+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Timestamp.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\TypedData\Type\Timestamp.
+ */
+
+namespace Drupal\Core\TypedData\Plugin\DataType;
+
+use Drupal\Core\TypedData\Annotation\DataType;
+use Drupal\Core\Annotation\Translation;
+use Drupal\Core\Datetime\DrupalDateTime;
+use Drupal\Core\TypedData\Type\DateTimeInterface;
+
+/**
+ * The timestamp data type.
+ *
+ * @DataType(
+ * id = "timestamp",
+ * label = @Translation("String")
+ * )
+ */
+class Timestamp extends Integer implements DateTimeInterface {
+
+ /**
+ * The data value as a UNIX timestamp.
+ *
+ * @var integer
+ */
+ protected $value;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getDateTime() {
+ if ($this->value) {
+ return new DrupalDateTime($this->value);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setDateTime(DrupalDateTime $dateTime) {
+ $this->value = $dateTime->getTimestamp();
+ }
+}