Skip to content

Commit

Permalink
Merge pull request #2 from sminnee/patch-1
Browse files Browse the repository at this point in the history
FIX: Represent dates as msec not seconds
  • Loading branch information
honzabrecka authored Jun 27, 2018
2 parents a72d821 + 155d1a1 commit 3e47498
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/transit/Transit.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ 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());
$this->registerHandler(new CharHandler());
$this->registerHandler(new TimestampHandler());
$this->registerHandler(new ArbitraryPrecisionDecimalHandler());
$this->registerHandler(new ArbitraryPrecisionIntegerHandler());
}
Expand Down
6 changes: 3 additions & 3 deletions src/transit/handlers/DateTimeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public function type() {
}

public function representation($obj) {
return $obj->getTimestamp();
return $obj->getTimestamp() * 1000;
}

public function resolve($obj) {
return new \DateTime('@' . $obj);
return new \DateTime('@' . $obj/1000);
}

}
}
4 changes: 2 additions & 2 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ function r($input) {
//-------------------------
// extensions

//Assert::equal('["~m482196050"]', w([new DateTime('1985-04-12T23:20:50.52Z')]));
//Assert::equal([new DateTime('1985-04-12T23:20:50.52Z')], r('["~m482196050"]'));
Assert::equal('["~m482196050000"]', w([new DateTime('1985-04-12T23:20:50.52Z')]));
Assert::equal((new DateTime('1985-04-12T23:20:50.52Z'))->getTimestamp(), r('["~m482196050000"]')[0]->getTimestamp());

Assert::equal('["~bYWJj"]', w([new Bytes('abc')]));
Assert::equal([new Bytes('abc')], r('["~bYWJj"]'));
Expand Down

0 comments on commit 3e47498

Please sign in to comment.