Skip to content

Commit

Permalink
[bug] RunContext::$duration can be negative under certain conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
gassan authored Oct 30, 2022
1 parent 13a8671 commit dd41eb6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Schedule/RunContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
abstract class RunContext
{
/** @var \DateTimeImmutable */
/** @var int */
private $startTime;

/** @var int|null */
Expand All @@ -20,14 +20,14 @@ abstract class RunContext

public function __construct()
{
$this->startTime = new \DateTimeImmutable('now');
$this->startTime = \time();
}

abstract public function __toString(): string;

final public function getStartTime(): \DateTimeImmutable
{
return $this->startTime;
return new \DateTimeImmutable('@'.$this->startTime);
}

final public function hasRun(): bool
Expand Down Expand Up @@ -61,7 +61,7 @@ final public function getFormattedMemory(): string

final protected function markAsRun(int $memory): void
{
$this->duration = \time() - $this->getStartTime()->getTimestamp();
$this->duration = \time() - $this->startTime;
$this->memory = $memory;
}

Expand Down

0 comments on commit dd41eb6

Please sign in to comment.