Skip to content

Commit

Permalink
FIX: ElapsedTime::toHumanMinial shows '0min' if seconds is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaail committed Oct 20, 2024
1 parent 65a00ce commit d6498a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Domain/Timelog/ValueObject/ElapsedTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function toHuman(): string

public function toHumanMinimal(): string
{
if (! $this->seconds) {
if (0 === $this->hours && 0 === $this->minutes) {
return '0 min';
}

$hours = $this->hours > 0 ? "{$this->hours}H" : '';
$minutes = $this->minutes > 0 ? "{$this->minutes}min" : '';

return "$hours $minutes";
return trim("$hours $minutes");
}
}
15 changes: 15 additions & 0 deletions tests/Unit/Timelog/ElapsedTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@
[180, 3],
[200, 3],
]);

it('shows time in Human Minimal Format', function (int $seconds, string $expectedTime): void {
$elapsedTime = ElapsedTime::fromSeconds($seconds);
expect($elapsedTime->toHumanMinimal())->toBe($expectedTime, message: "Wrong Human Minimal Format for '$seconds' seconds.");
})->with([
[0, '0 min'],
[59, '0 min'],
[60, '1min'],
[120, '2min'],
[3599, '59min'],
[3600, '1H'],
[3659, '1H'],
[3660, '1H 1min'],
[4200, '1H 10min'],
]);

0 comments on commit d6498a0

Please sign in to comment.