Skip to content

Commit

Permalink
Add support for Carbon 3 and fix php8.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMuller committed Jul 30, 2024
1 parent 868b63c commit 85c5247
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 4 additions & 6 deletions src/Stopwatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Exception;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Htmlable;
use Override;
use Stringable;

/**
Expand Down Expand Up @@ -91,13 +90,15 @@ public function totalRunDuration(): CarbonInterval
throw new Exception('Stopwatch has not been finished yet.');
}

return $this->endTime->diffAsCarbonInterval($this->startTime);
return $this->endTime->diffAsCarbonInterval($this->startTime, absolute: true);
});
}

private function totalRunDurationReadable(): string
{
return "{$this->totalRunDuration()->totalMilliseconds}ms";
$ms = round($this->totalRunDuration()->totalMilliseconds, 1);

return "{$ms}ms";
}

public function dd(mixed ...$args): never
Expand All @@ -116,7 +117,6 @@ public function dump(mixed ...$args): self
return $this;
}

#[Override]
public function toHtml(): string
{
$this->finish();
Expand Down Expand Up @@ -183,7 +183,6 @@ public function toString(): string
return $this->totalRunDurationReadable();
}

#[Override]
public function __toString(): string
{
return $this->toString();
Expand All @@ -198,7 +197,6 @@ public function __toString(): string
* totalRunDurationMs: int,
* }
*/
#[Override]
public function toArray(): array
{
$this->finish();
Expand Down
6 changes: 2 additions & 4 deletions src/StopwatchCheckpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Carbon\CarbonImmutable;
use Carbon\CarbonInterval;
use Illuminate\Contracts\Support\Arrayable;
use Override;
use Stringable;

/**
Expand Down Expand Up @@ -34,10 +33,10 @@ public function __construct(
) {
$this->time = CarbonImmutable::now();

$this->timeSinceStopwatchStart = $this->time->diffAsCarbonInterval($stopwatchStartTime)->cascade();
$this->timeSinceStopwatchStart = $this->time->diffAsCarbonInterval($stopwatchStartTime, absolute: true)->cascade();

$this->timeSinceLastCheckpoint = $previousCheckpoint !== null
? $this->time->diffAsCarbonInterval($previousCheckpoint->time)->cascade()
? $this->time->diffAsCarbonInterval($previousCheckpoint->time, absolute: true)->cascade()
: $this->timeSinceStopwatchStart;

$this->timeSinceLastCheckpointFormatted = round($this->timeSinceLastCheckpoint->totalMilliseconds, 1) . 'ms';
Expand Down Expand Up @@ -117,7 +116,6 @@ private function renderMetadata(): string
* timeSinceLastCheckpointFormatted: string,
* }
*/
#[Override]
public function toArray(): array
{
return [
Expand Down

0 comments on commit 85c5247

Please sign in to comment.