1 | <?php |
||
17 | class Duration |
||
18 | { |
||
19 | /** |
||
20 | * @var int timestamp interval |
||
21 | */ |
||
22 | public $interval = 0; |
||
23 | |||
24 | /** |
||
25 | * @var int save interval when using format mode |
||
26 | */ |
||
27 | private $tempInterval = 0; |
||
28 | |||
29 | /** |
||
30 | * @var string used format for forming the output |
||
31 | */ |
||
32 | public $format = ''; |
||
33 | |||
34 | /** |
||
35 | * @param int $interval timestamp interval |
||
36 | * @param \DateTime $interval the first date |
||
37 | */ |
||
38 | 9 | public function __construct($interval = 0) |
|
47 | |||
48 | /** |
||
49 | * @param int $interval set current time interval |
||
50 | * |
||
51 | * @return self object |
||
52 | */ |
||
53 | public function setInterval($interval) |
||
59 | |||
60 | /** |
||
61 | * @param string $format set current format |
||
62 | * |
||
63 | * @return self object |
||
64 | */ |
||
65 | public function setFormat($format) |
||
71 | |||
72 | /** |
||
73 | * @param int $round_method rounding method after we reveal the readable |
||
74 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
75 | * |
||
76 | * @return float in seconds |
||
77 | */ |
||
78 | 5 | public function getSeconds($round_method = null) |
|
84 | |||
85 | /** |
||
86 | * @param int $round_method rounding method after we reveal the readable |
||
87 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
88 | * |
||
89 | * @return float in minutes |
||
90 | */ |
||
91 | 5 | public function getMinutes($round_method = null) |
|
97 | |||
98 | /** |
||
99 | * @param int $round_method rounding method after we reveal the readable |
||
100 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
101 | * |
||
102 | * @return float in hours |
||
103 | */ |
||
104 | 5 | public function getHours($round_method = null) |
|
110 | |||
111 | /** |
||
112 | * @param string $format rounding method after we reveal the readable |
||
113 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
114 | * |
||
115 | * @return well formatted output |
||
116 | */ |
||
117 | 3 | public function format($format = []) |
|
152 | |||
153 | /** |
||
154 | * @param int $round_method rounding method after we reveal the readable |
||
155 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
156 | * |
||
157 | * @return float current number of the result. if it is using $round_method, |
||
158 | * it will rounded up or down |
||
159 | */ |
||
160 | 9 | private function round($result, $round_method = null) |
|
170 | |||
171 | /** |
||
172 | * @return well formatted output |
||
173 | */ |
||
174 | public function __toString() |
||
178 | |||
179 | /** |
||
180 | * Fix singulars of time units |
||
181 | * |
||
182 | * @param string $string |
||
183 | * @return string Formatted string with replaced plurals to singular |
||
184 | */ |
||
185 | 3 | protected function fixSingulars($string) |
|
192 | } |
||
193 |