| 1 |
<?php |
| 2 |
/** |
| 3 |
* Formats a duration in a human-readable format. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Timer; |
| 11 |
|
| 12 |
/** |
| 13 |
* Formats a duration in a human-readable format. |
| 14 |
* |
| 15 |
* @package SolidWP\Performance |
| 16 |
*/ |
| 17 |
final class Duration { |
| 18 |
|
| 19 |
/** |
| 20 |
* The duration in seconds. |
| 21 |
* |
| 22 |
* @var float |
| 23 |
*/ |
| 24 |
private float $seconds; |
| 25 |
|
| 26 |
/** |
| 27 |
* @param float $seconds The duration in seconds. |
| 28 |
*/ |
| 29 |
public function __construct( float $seconds ) { |
| 30 |
$this->seconds = $seconds; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Format the duration in human-readable form. |
| 35 |
* |
| 36 |
* @return string In the format of: 2 hours, 14 minutes, 9 seconds |
| 37 |
*/ |
| 38 |
public function format(): string { |
| 39 |
return human_readable_duration( gmdate( 'H:i:s', (int) $this->seconds ) ); |
| 40 |
} |
| 41 |
} |
| 42 |
|