Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Stopwatch] StopwatchEvent->getStartTime() is incorrect #34088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sirian opened this issue Oct 23, 2019 · 1 comment
Closed

[Stopwatch] StopwatchEvent->getStartTime() is incorrect #34088

sirian opened this issue Oct 23, 2019 · 1 comment

Comments

@sirian
Copy link
Contributor

sirian commented Oct 23, 2019

Symfony version(s) affected: ^4.3

How to reproduce

$event = new \Symfony\Component\Stopwatch\StopwatchEvent(0, null, true);

$event->start();
usleep(100000);
var_dump($event->getStartTime());
$event->stop();
var_dump($event->getStartTime());

Output:

int(0); // But should not be 0
float(1571838784644.8)

Possible solutions

Bug lives here https://github.com/symfony/stopwatch/blob/9e2c41817c3e3d506e5db1d052cbfbbc6f685199/StopwatchEvent.php#L157

     public function getStartTime()
    {
        return isset($this->periods[0]) ? $this->periods[0]->getStartTime() : 0;
    }

Should be

    public function getStartTime()
    {
        if (isset($this->periods[0])) {
            return $this->periods[0]->getStartTime();
        }
        if (\count($this->started)) {
            return $this->started[0];
        }
        return 0;
    }
@TimoBakx
Copy link
Member

I confirmed this bug in a test. Also affects Symfony 3.4.
Made a PR with proposed fix, which works correctly.

@fabpot fabpot closed this as completed Nov 3, 2019
fabpot added a commit that referenced this issue Nov 3, 2019
…imoBakx)

This PR was merged into the 3.4 branch.

Discussion
----------

[Stopwatch] Fixed a bug in StopwatchEvent::getStartTime

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34088
| License       | MIT
| Doc PR        | N/A

When using a `StopwatchEvent` with an `$origin` that's smaller than the first start time, calling `getStartTime()` before ending the event will give `0` instead of the correct number.

The proposed fix in #34088 fixes this.

Commits
-------

b2b7eab [Stopwatch] Fixed a bug in stopwatch event getStartTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants