-
Notifications
You must be signed in to change notification settings - Fork 82
Fix bug that can cause the timestamp to be 1 second later. #161
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks!
src/Trace/Span.php
Outdated
} elseif (!$when instanceof \DateTimeInterface) { | ||
throw new \InvalidArgumentException('Invalid date format. Must be a \DateTimeInterface or numeric.'); | ||
} | ||
$when->setTimezone(new \DateTimeZone('UTC')); | ||
return $when; | ||
} | ||
|
||
/** | ||
* Converst a float timestamp into a \DateTimeInterface object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: Converst -> Convert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Oops, we aren't providing env var credentials to forked builds for CI - investigating. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style checker found issues (via CI)
To run: vendor/bin/phpcs --standard=phpcs-ruleset.xml
I'll add something to the README/CONTRIBUTING guide on running the tests.
src/Trace/Span.php
Outdated
} elseif (!$when instanceof \DateTimeInterface) { | ||
throw new \InvalidArgumentException('Invalid date format. Must be a \DateTimeInterface or numeric.'); | ||
} | ||
$when->setTimezone(new \DateTimeZone('UTC')); | ||
return $when; | ||
} | ||
|
||
/** | ||
* Converts a float timestamp into a \DateTimeInterface object. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP code style enforcer found: extra whitespace at end of this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/Trace/Span.php
Outdated
* @param float $when The Unix timestamp to be converted. | ||
* @return \DateTimeInterface | ||
*/ | ||
private function formatFloatTimeToDate($when) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP code style enforcer found: opening brace should go on new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thanks @chingor13, unfortunately I couldn't find instructions to do this format checks and run tests, etc. and I am super new in php so I have no idea what to do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, code review fail by me.
src/Trace/Span.php
Outdated
list($usec, $sec) = explode(' ', microtime()); | ||
$micro = sprintf("%06d", $usec * 1000000); | ||
$when = new \DateTime(date('Y-m-d H:i:s.' . $micro)); | ||
$when = formatFloatTimeToDate(microtime(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$when = $this->formatFloatTimeToDate(microtime(true));
src/Trace/Span.php
Outdated
// Expect that this is a timestamp | ||
$micro = sprintf("%06d", ($when - floor($when)) * 1000000); | ||
$when = new \DateTime(date('Y-m-d H:i:s.'. $micro, (int) $when)); | ||
$when = formatFloatTimeToDate($when); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$when = $this->formatFloatTimeToDate($when);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This can happen because time was read twice when $when was null, once to get the usec and once to get the seconds, so if the initial time was 1.999 and second time was 2.001 then the result will be 2.999 which is 1 second later.