Conditions | 6 |
Paths | 6 |
Total Lines | 26 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
77 | 2 | public function getTimeDiff(\DateTime $releaseDate): string |
|
78 | { |
||
79 | 2 | $now = new \DateTime(); |
|
80 | 2 | $diff = $now->diff($releaseDate); |
|
81 | |||
82 | 2 | if ($diff->days > 7) { |
|
83 | 2 | return ''; |
|
84 | } |
||
85 | |||
86 | 1 | if ($diff->days == 7) { |
|
87 | 1 | return 'a week ago'; |
|
88 | } |
||
89 | |||
90 | 1 | if ($diff->days >= 1) { |
|
91 | 1 | return sprintf('%d day(s) ago', $diff->days); |
|
92 | } |
||
93 | |||
94 | 1 | if ($diff->h >= 1) { |
|
95 | 1 | return sprintf('%d hour(s) ago', $diff->h); |
|
96 | } |
||
97 | |||
98 | 1 | if ($diff->i >= 1) { |
|
99 | 1 | return sprintf('%d minute(s) ago', $diff->i); |
|
100 | } |
||
101 | |||
102 | 1 | return 'just now'; |
|
103 | } |
||
105 |