| Conditions | 5 |
| Paths | 8 |
| Total Lines | 29 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 5.025 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | function humanizeDateDiff(Date $datetime, Date $origin = null) : string |
||
| 16 | { |
||
| 17 | 4 | if (!isset($origin)) { |
|
| 18 | 4 | $origin = new Date(); |
|
| 19 | } |
||
| 20 | 4 | $interval = $datetime->diff($origin); |
|
| 21 | |||
| 22 | 4 | $d = $interval->d; |
|
| 23 | 4 | $h = $interval->h; |
|
| 24 | 4 | $m = $interval->i; |
|
| 25 | 4 | $s = $interval->s; |
|
| 26 | |||
| 27 | 4 | if ($d > 0) { |
|
| 28 | 4 | $unit = 'day'; |
|
| 29 | 4 | $count = $d; |
|
| 30 | 2 | } elseif ($h > 0) { |
|
| 31 | 2 | $unit = 'hour'; |
|
| 32 | 2 | $count = $h; |
|
| 33 | 2 | } elseif ($m > 0) { |
|
| 34 | 2 | $unit = 'minute'; |
|
| 35 | 2 | $count = $m; |
|
| 36 | } else { |
||
| 37 | $unit = 'second'; |
||
| 38 | $count = $s; |
||
| 39 | } |
||
| 40 | |||
| 41 | 4 | $key = "common/time.$unit"; |
|
| 42 | |||
| 43 | 4 | return Lang::choice($key, $count); |
|
| 44 | } |
||
| 46 |