Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| DateHelper | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 1 |
| getLabelByInterval | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
56 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Helpers; |
| 4 | |
| 5 | class DateHelper |
| 6 | { |
| 7 | public static function getLabelByInterval($intervalInMonths) |
| 8 | { |
| 9 | if ($intervalInMonths < 12) { |
| 10 | return "{$intervalInMonths} month" . ($intervalInMonths > 1 ? 's' : ''); |
| 11 | } else if ($intervalInMonths == 12) { |
| 12 | return "1 year"; |
| 13 | } else { |
| 14 | $years = floor($intervalInMonths / 12); |
| 15 | $months = $intervalInMonths % 12; |
| 16 | |
| 17 | $label = "{$years} year" . ($years > 1 ? 's' : ''); |
| 18 | |
| 19 | if ($months > 0) { |
| 20 | $label .= " {$months} month" . ($months > 1 ? 's' : ''); |
| 21 | } |
| 22 | |
| 23 | return $label; |
| 24 | } |
| 25 | } |
| 26 | } |