| 1 | <?php |
||
| 5 | class Timer |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var double |
||
| 9 | */ |
||
| 10 | private $start; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var double |
||
| 14 | */ |
||
| 15 | private $time; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $format; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Create a new Timer instance and start it. |
||
| 24 | * |
||
| 25 | * @param string $format |
||
| 26 | */ |
||
| 27 | 30 | public function __construct($format = 'H:i:s.ms') |
|
| 31 | |||
| 32 | /** |
||
| 33 | * Set the date format. |
||
| 34 | * |
||
| 35 | * @param string $format |
||
| 36 | * @return $this |
||
| 37 | */ |
||
| 38 | 30 | protected function format($format) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * Start the timer. |
||
| 46 | * |
||
| 47 | * @return $this |
||
| 48 | */ |
||
| 49 | 30 | public function start() |
|
| 54 | |||
| 55 | /** |
||
| 56 | * Stop the timer. |
||
| 57 | * |
||
| 58 | * @return $this |
||
| 59 | */ |
||
| 60 | 30 | public function stop() |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Reset the timer. |
||
| 68 | * |
||
| 69 | * @return $this |
||
| 70 | */ |
||
| 71 | 3 | public function reset() |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Return measured time. |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | 30 | public function time() |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Replace the date format with calculated values. |
||
| 96 | * |
||
| 97 | * @param string $pattern |
||
| 98 | * @param int $precision |
||
| 99 | * @param string $format |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | 30 | private function replace($pattern, $precision, $format) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Stop the timer and return measured time. |
||
| 111 | * |
||
| 112 | * @return string |
||
| 113 | */ |
||
| 114 | 21 | public function end() |
|
| 118 | } |
||
| 119 |