Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Add support for start times in microseconds. #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions ApplicationInsights/Channel/Contracts/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@ public static function convertMillisecondsToTimeSpan($milliseconds)
* @return string
*/
public static function returnISOStringForTime($time = null)
{
{
if ($time == NULL)
{
return gmdate('c') . 'Z';
}
else
{
return gmdate('c', $time) . 'Z';
$time = microtime(true);
}
$microseconds = substr(sprintf('%06d', round($time-floor($time), 6)*1000000), 0, 6);
gmdate("Y-m-d\TH:i:s.", $time).$microseconds.'+00:00Z'; //iso 8601 GMT with microseconds
}

/**
Expand Down
7 changes: 7 additions & 0 deletions Tests/Channel/Contracts/Utils_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ public function testConvertMillisecondsToTimeSpan()
$this->assertEquals(Utils::convertMillisecondsToTimeSpan(-1), "00:00:00.000", "invalid input");

}
public function testReturnISOStringForTime()
{
$date = (new DateTime("2004-02-12T15:19:21+00:00"))->getTimestamp();
$this->assertEquals(Utils::returnISOStringForTime($date), "2004-02-12T15:19:21.000000+00:00Z");
$this->assertEquals(Utils::returnISOStringForTime($date+0.1), "2004-02-12T15:19:21.100000+00:00Z", "milliseconds digit 1");
$this->assertEquals(Utils::returnISOStringForTime($date+0.999999), "2004-02-12T15:19:21.999999+00:00Z", "rounding error");
}
}