From 19e141801771a0a0957f2e6e6fc27a5751ceff54 Mon Sep 17 00:00:00 2001 From: Jan Brecka Date: Mon, 20 Nov 2023 19:38:13 +0100 Subject: [PATCH] fix timestamp --- src/transit/Timestamp.php | 24 ---------------------- src/transit/Transit.php | 2 -- src/transit/handlers/DateTimeHandler.php | 4 ++-- src/transit/handlers/TimestampHandler.php | 25 ----------------------- test/test.php | 3 +++ 5 files changed, 5 insertions(+), 53 deletions(-) delete mode 100644 src/transit/Timestamp.php delete mode 100644 src/transit/handlers/TimestampHandler.php diff --git a/src/transit/Timestamp.php b/src/transit/Timestamp.php deleted file mode 100644 index 84ad4d4..0000000 --- a/src/transit/Timestamp.php +++ /dev/null @@ -1,24 +0,0 @@ -validate($value); - $this->value = $value; - } - - private function validate($value) { - if (!is_string($value)) { - throw new TransitException('Invalid timestamp.'); - } - } - - public function __toString() { - return $this->value; - } - -} diff --git a/src/transit/Transit.php b/src/transit/Transit.php index 8be6167..c2d1b2c 100644 --- a/src/transit/Transit.php +++ b/src/transit/Transit.php @@ -13,7 +13,6 @@ use transit\handlers\URIHandler; use transit\handlers\UUIDHandler; use transit\handlers\CharHandler; -use transit\handlers\TimestampHandler; use transit\handlers\ArbitraryPrecisionDecimalHandler; use transit\handlers\ArbitraryPrecisionIntegerHandler; @@ -53,7 +52,6 @@ private function registerDefaultHandlers() { $this->registerHandler(new SymbolHandler()); $this->registerHandler(new SetHandler()); $this->registerHandler(new ListHandler()); - $this->registerHandler(new TimestampHandler()); $this->registerHandler(new DateTimeHandler()); $this->registerHandler(new URIHandler()); $this->registerHandler(new UUIDHandler()); diff --git a/src/transit/handlers/DateTimeHandler.php b/src/transit/handlers/DateTimeHandler.php index 5ef693e..d785388 100644 --- a/src/transit/handlers/DateTimeHandler.php +++ b/src/transit/handlers/DateTimeHandler.php @@ -13,11 +13,11 @@ public function type() { } public function representation($obj) { - return $obj->getTimestamp() * 1000; + return $obj->getTimestamp(); } public function resolve($obj) { - return new \DateTime('@' . $obj/1000); + return new \DateTime('@' . $obj); } } diff --git a/src/transit/handlers/TimestampHandler.php b/src/transit/handlers/TimestampHandler.php deleted file mode 100644 index ee55091..0000000 --- a/src/transit/handlers/TimestampHandler.php +++ /dev/null @@ -1,25 +0,0 @@ -getTimestamp(), r('["~m482196050000"]')[0]->getTimestamp()); +$timestamp = "[\"~#'\",\"~m1776669847291\"]"; +Assert::equal($timestamp, w(r($timestamp))); + Assert::equal('["~bYWJj"]', w([new Bytes('abc')])); Assert::equal([new Bytes('abc')], r('["~bYWJj"]'));