Conditions | 6 |
Paths | 16 |
Total Lines | 22 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
17 | public function timeAgo($datetime_to, $datetime_from = null, $full = false) |
||
18 | { |
||
19 | $now = $this->getNow($datetime_from); |
||
20 | $ago = new \DateTime($datetime_to); |
||
21 | $diff = $now->diff($ago); |
||
22 | |||
23 | $diff->w = floor($diff->d / 7); |
||
|
|||
24 | $diff->d -= $diff->w * 7; |
||
25 | |||
26 | foreach ($this->string as $k => &$v) { |
||
27 | if ($diff->$k) { |
||
28 | $v = $diff->$k.' '.$v.($diff->$k > 1 ? 's' : ''); |
||
29 | } else { |
||
30 | unset($this->string[$k]); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | if (! $full) { |
||
35 | $this->string = array_slice($this->string, 0, 1); |
||
36 | } |
||
37 | |||
38 | return $this->string ? implode(', ', $this->string).' ' : 'just now'; |
||
39 | } |
||
55 | } |