From d8fd5f6ca13d7d8bb8c9a262b402c1384a69c1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Leutg=C3=B6b?= Date: Thu, 7 Sep 2017 13:59:16 +0200 Subject: [PATCH] Fix timestamp implementation for microseconds Following changes and fixed issues are included: - Line 134: Wrong php method reference - Line 162: The cast to int is redundant as seconds are already casted in date() call at line 165 - Line 163: Casting microseconds part to int strips out leading zeros, resulting in converting a timestamp from `1504784759.0124` to `1504784759.124` as an example. - Line 614: The date format string misses the dot as separator between seconds and microseconds, resulting in datetime object far in the future when parsing in `send.php` (File consumer) --- lib/Segment/Client.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Segment/Client.php b/lib/Segment/Client.php index c421bfe..99c3bee 100644 --- a/lib/Segment/Client.php +++ b/lib/Segment/Client.php @@ -131,7 +131,7 @@ public function flush() { * Formats a timestamp by making sure it is set * and converting it to iso8601. * - * The timestamp can be time in seconds `time()` or `microseconds(true)`. + * The timestamp can be time in seconds `time()` or `microtime(true)`. * any other input is considered an error and the method will return a new date. * * Note: php's date() "u" format (for microseconds) has a bug in it @@ -159,9 +159,9 @@ private function formatTime($ts) { if (!isset($parts[1])) return date("c", (int)$parts[0]); // microtime(true) - $sec = (int)$parts[0]; - $usec = (int)$parts[1]; - $fmt = sprintf("Y-m-d\TH:i:s%sP", $usec); + $sec = $parts[0]; + $usec = $parts[1]; + $fmt = sprintf("Y-m-d\TH:i:s.%sP", $usec); return date($fmt, (int)$sec); }