| Conditions | 5 |
| Paths | 4 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | protected function timeToIso8601Duration($time) |
||
| 45 | { |
||
| 46 | $units = array( |
||
| 47 | "Y" => 365*24*3600, |
||
| 48 | "D" => 24*3600, |
||
| 49 | "H" => 3600, |
||
| 50 | "M" => 60, |
||
| 51 | "S" => 1, |
||
| 52 | ); |
||
| 53 | |||
| 54 | $str = "P"; |
||
| 55 | $istime = false; |
||
| 56 | |||
| 57 | foreach ($units as $unitName => &$unit) { |
||
| 58 | $quot = intval($time / $unit); |
||
| 59 | $time -= $quot * $unit; |
||
| 60 | $unit = $quot; |
||
| 61 | if ($unit > 0) { |
||
| 62 | if (!$istime && in_array($unitName, array("H", "M", "S"))) { // There may be a better way to do this |
||
| 63 | $str .= "T"; |
||
| 64 | $istime = true; |
||
| 65 | } |
||
| 66 | $str .= strval($unit) . $unitName; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | return $str; |
||
| 71 | } |
||
| 72 | } |