Conditions | 9 |
Paths | 32 |
Total Lines | 32 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
17 | function smarty_modifier_timeago($timestamp) { |
||
18 | $date = new \DateTime(); |
||
19 | $now = $date->format('U'); |
||
20 | $message = ""; |
||
21 | |||
22 | if ($now-$timestamp <60) { |
||
23 | $diff = $now-$timestamp; |
||
24 | $message .= " $diff seconds ago"; |
||
25 | } |
||
26 | if ($now-$timestamp >60 and $now-$timestamp <3600) { |
||
27 | $diff = $now-$timestamp; |
||
28 | $diff = floor($diff / 60); |
||
29 | $message .= " $diff minutes ago"; |
||
30 | } |
||
31 | if ($now-$timestamp >3600 and $now-$timestamp <86400) { |
||
32 | $diff = $now-$timestamp; |
||
33 | $diff = floor($diff / 3600); |
||
34 | $message .= " $diff hours ago"; |
||
35 | } |
||
36 | if ($now-$timestamp >86400 and $now-$timestamp <172800) { |
||
37 | $diff = $now-$timestamp; |
||
38 | $diff = floor($diff / 3600); |
||
|
|||
39 | $message .= " yesterday"; |
||
40 | } |
||
41 | if ($now-$timestamp >172800) { |
||
42 | $time = new \DateTime(); |
||
43 | $time->setTimestamp($timestamp); |
||
44 | $change_date = $time->format('M d'); |
||
45 | $message .= " on $change_date"; |
||
46 | } |
||
47 | |||
48 | return $message; |
||
49 | } |
||
50 |