| 1 | <?php |
||
| 5 | class Time |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Transform tm timestamp to mm:ss.ccc string |
||
| 9 | * |
||
| 10 | * @param int $time |
||
| 11 | * @param bool $milliseconds |
||
| 12 | * |
||
| 13 | * @return string |
||
| 14 | */ |
||
| 15 | 1 | public function timeToText($time, $milliseconds = false) |
|
| 16 | { |
||
| 17 | 1 | $time = intval($time); |
|
| 18 | 1 | $ms = ""; |
|
| 19 | 1 | if ($milliseconds) { |
|
| 20 | 1 | $ms = ".".str_pad((abs($time) % 1000), 3, '0', STR_PAD_LEFT); |
|
| 21 | 1 | } |
|
| 22 | 1 | if ($time > 0) { |
|
| 23 | 1 | return gmdate("i:s", $time / 1000).$ms; |
|
| 24 | } else { |
||
| 25 | 1 | return "-".gmdate("i:s", abs($time / 1000)).$ms; |
|
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Transform mm:ss to tm timestamp |
||
| 31 | * |
||
| 32 | * @param string $string formatted like mm:ss |
||
| 33 | * |
||
| 34 | * @return int |
||
| 35 | */ |
||
| 36 | 1 | public function textToTime($string) |
|
| 45 | } |
||
| 46 |