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 | * @param DateTime $last_date the last date so we can find the interval of |
||
38 | * the first and the last date |
||
39 | * |
||
40 | * @return self object |
||
|
|||
41 | */ |
||
42 | 10 | public function __construct($interval = 0, \DateTime $last_date = null) |
|
53 | |||
54 | /** |
||
55 | * @param int $interval set current time interval |
||
56 | * |
||
57 | * @return self object |
||
58 | */ |
||
59 | public function setInterval($interval) |
||
65 | |||
66 | /** |
||
67 | * @param string $format set current format |
||
68 | * |
||
69 | * @return self object |
||
70 | */ |
||
71 | public function setFormat($format) |
||
77 | |||
78 | /** |
||
79 | * @param int $round_method rounding method after we reveal the readable |
||
80 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
81 | * |
||
82 | * @return float in seconds |
||
83 | */ |
||
84 | 6 | public function getSeconds($round_method = null) |
|
90 | |||
91 | /** |
||
92 | * @param int $round_method rounding method after we reveal the readable |
||
93 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
94 | * |
||
95 | * @return float in minutes |
||
96 | */ |
||
97 | 6 | public function getMinutes($round_method = null) |
|
103 | |||
104 | /** |
||
105 | * @param int $round_method rounding method after we reveal the readable |
||
106 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
107 | * |
||
108 | * @return float in hours |
||
109 | */ |
||
110 | 6 | public function getHours($round_method = null) |
|
116 | |||
117 | /** |
||
118 | * @param string $format rounding method after we reveal the readable |
||
119 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
120 | * |
||
121 | * @return well formatted output |
||
122 | */ |
||
123 | 4 | public function format($format = []) |
|
159 | |||
160 | /** |
||
161 | * @param int $round_method rounding method after we reveal the readable |
||
162 | * interval. You can use PHP_ROUND_HALF_UP and PHP_ROUND_HALF_DOWN |
||
163 | * |
||
164 | * @return float current number of the result. if it is using $round_method, |
||
165 | * it will rounded up or down |
||
166 | */ |
||
167 | 10 | private function round($result, $round_method = null) |
|
177 | |||
178 | /** |
||
179 | * @return well formatted output |
||
180 | */ |
||
181 | public function __toString() |
||
185 | |||
186 | /** |
||
187 | * Fix singulars of time units |
||
188 | * |
||
189 | * @param string $string |
||
190 | * @return string Formatted string with replaced plurals to singular |
||
191 | */ |
||
192 | 4 | protected function fixSingulars($string) |
|
199 | } |
||
200 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.