From c162760ab838dd62f96a08d9f1a6f95a8a0c8cba Mon Sep 17 00:00:00 2001 From: Walter Dal Mut Date: Sat, 13 Jun 2015 11:04:11 +0200 Subject: [PATCH 1/2] Fixes time generation for udp/ip packets Uses microtimes instead of Datetime --- src/Adapter/UdpAdapter.php | 3 +-- tests/ClientTest.php | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Adapter/UdpAdapter.php b/src/Adapter/UdpAdapter.php index bc9004ee30..e497b13b76 100644 --- a/src/Adapter/UdpAdapter.php +++ b/src/Adapter/UdpAdapter.php @@ -28,8 +28,7 @@ final class UdpAdapter extends AdapterAbstract $tags = array_replace_recursive($tags, $message["tags"]); } - $now = new DateTime(); - $unixepoch = (int)($now->format("U") * 1e9); + $unixepoch = (int)(microtime(true) * 1e9); if (array_key_exists("time", $message)) { $dt = new DateTime($message["time"]); $unixepoch = (int)($dt->format("U") * 1e9); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 1bfb33db3d..ad5367b2e9 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -2,6 +2,7 @@ namespace InfluxDB; use DateTime; +use DateTimeZone; use InfluxDB\Adapter\GuzzleAdapter as InfluxHttpAdapter; use InfluxDB\Options; use InfluxDB\Adapter\UdpAdapter; @@ -165,11 +166,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase $object = $this->createClientWithUdpAdapter(); $object->mark("udp.test", ["mark" => "element"]); - sleep(1); $object->mark("udp.test", ["mark" => "element1"]); - sleep(1); $object->mark("udp.test", ["mark" => "element2"]); - sleep(1); $object->mark("udp.test", ["mark" => "element3"]); // Wait UDP/IP message arrives @@ -278,8 +276,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertCount(1, $body["results"][0]["series"][0]["values"]); $this->assertEquals("time", $body["results"][0]["series"][0]["columns"][0]); - $saved = new DateTime($body["results"][0]["series"][0]["values"][0][0]); - $this->assertEquals(date("Y-m-d"), $saved->format("Y-m-d")); + $saved = $body["results"][0]["series"][0]["values"][0][0]; + $this->assertRegExp("/".date("Y-m-d")."/i", $saved); } /** From b2f044f15459027700befd01776b0e618d79e9a1 Mon Sep 17 00:00:00 2001 From: Walter Dal Mut Date: Sat, 13 Jun 2015 11:24:13 +0200 Subject: [PATCH 2/2] Bumped version 0.4.3 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 2b7c5ae018..17b2ccd9bf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.2 +0.4.3