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() |
|
67 | |||
68 | /** |
||
69 | * Reset the timer. |
||
70 | * |
||
71 | * @return $this |
||
72 | */ |
||
73 | 3 | public function reset() |
|
79 | |||
80 | /** |
||
81 | * Return measured time. |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | 30 | public function time() |
|
95 | |||
96 | /** |
||
97 | * Replace the date format with calculated values. |
||
98 | * |
||
99 | * @param string $pattern |
||
100 | * @param int $precision |
||
101 | * @param string $format |
||
102 | * @return string |
||
103 | */ |
||
104 | 30 | private function replace($pattern, $precision, $format) |
|
110 | |||
111 | /** |
||
112 | * Stop the timer and return measured time. |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 21 | public function end() |
|
120 | } |
||
121 |