| Conditions | 6 |
| Paths | 16 |
| Total Lines | 21 |
| 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->d -= floor($diff->d / 7) * 7; |
||
| 24 | |||
| 25 | foreach ($this->string as $k => &$v) { |
||
| 26 | if ($diff->$k) { |
||
| 27 | $v = $diff->$k.' '.$v.($diff->$k > 1 ? 's' : ''); |
||
| 28 | } else { |
||
| 29 | unset($this->string[$k]); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | if (! $full) { |
||
| 34 | $this->string = array_slice($this->string, 0, 1); |
||
| 35 | } |
||
| 36 | |||
| 37 | return $this->string ? implode(', ', $this->string).' ' : 'just now'; |
||
| 38 | } |
||
| 54 | } |