Skip to content

Commit

Permalink
fixed notNotButRightNow method which was not always returning a prope…
Browse files Browse the repository at this point in the history
…r DateTime with milliseconds. Also fixed the name of the method which was misspelled
  • Loading branch information
enobrev committed Feb 21, 2018
1 parent 4112cd1 commit a7847fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use DateTime;

/**
* https://stackoverflow.com/a/29598719/14651
*
* Returns DateTime object with proper microtime
* @return DateTime
*/
function notNowByRightNow() {
$aMicroTime = explode(' ', microtime());
$iMicroSeconds = (int) $aMicroTime[0] * 1000000;
return new DateTime(date('Y-m-d H:i:s.' . $iMicroSeconds, (int) $aMicroTime[1]));
function notNowButRightNow() {
return DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
}
6 changes: 3 additions & 3 deletions src/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private static function getThreadHash(): string {
} else if (isset($_SERVER['NGINX_REQUEST_ID'])) {
self::$sThreadHash = $_SERVER['NGINX_REQUEST_ID'];
} else {
self::$sThreadHash = substr(hash('sha1', notNowByRightNow()->format('Y-m-d G:i:s.u')), 0, 6);
self::$sThreadHash = substr(hash('sha1', notNowButRightNow()->format('Y-m-d G:i:s.u')), 0, 6);
}

return self::$sThreadHash;
Expand All @@ -373,7 +373,7 @@ private static function getThreadHash(): string {
* @param array $aContext
*/
public static function initSpan(array $aContext = []): void {
$oStartTime = notNowByRightNow();
$oStartTime = notNowButRightNow();
$sIP = get_ip();
$aRequestDetails = [
'date' => $oStartTime->format('Y-m-d H:i:s.u')
Expand Down Expand Up @@ -456,7 +456,7 @@ public static function summary(string $sOverrideName = 'Summary'): void {
[
'_format' => 'SSFSpan.DashedTrace',
'version' => 1,
'end_timestamp' => notNowByRightNow()->format(self::TIMESTAMP_FORMAT),
'end_timestamp' => notNowButRightNow()->format(self::TIMESTAMP_FORMAT),
'service' => self::$sService,
'indicator' => false
],
Expand Down

0 comments on commit a7847fb

Please sign in to comment.