mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 02:44:53 +00:00
Added TimeAgo Function to convert mysql DataTime to a human readable time like 2 weeks ago similar to other apps like facebook do it. Added to function to Recent Activity under client overview
This commit is contained in:
@@ -653,3 +653,29 @@ function sanitizeForEmail($data) {
|
||||
$sanitized = trim($sanitized);
|
||||
return $sanitized;
|
||||
}
|
||||
|
||||
function timeAgo($datetime) {
|
||||
$time = strtotime($datetime);
|
||||
$difference = time() - $time;
|
||||
|
||||
if ($difference < 1) {
|
||||
return 'just now';
|
||||
}
|
||||
$timeRules = array (
|
||||
31536000 => 'year',
|
||||
2592000 => 'month',
|
||||
604800 => 'week',
|
||||
86400 => 'day',
|
||||
3600 => 'hour',
|
||||
60 => 'minute',
|
||||
1 => 'second'
|
||||
);
|
||||
|
||||
foreach ($timeRules as $secs => $str) {
|
||||
$div = $difference / $secs;
|
||||
if ($div >= 1) {
|
||||
$t = round($div);
|
||||
return $t . ' ' . $str . ($t > 1 ? 's' : '') . ' ago';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user