mirror of https://github.com/itflow-org/itflow
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:
parent
ca61556c4f
commit
f64ab630fd
|
|
@ -114,13 +114,12 @@ $sql_asset_retire = mysqli_query(
|
|||
<?php
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_recent_activities)) {
|
||||
$log_id = intval($row['log_id']);
|
||||
$log_created_at = nullable_htmlentities($row['log_created_at']);
|
||||
$log_created_at_time_ago = timeAgo($row['log_created_at']);
|
||||
$log_description = nullable_htmlentities($row['log_description']);
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $log_created_at; ?></td>
|
||||
<td><?php echo $log_created_at_time_ago; ?></td>
|
||||
<td><?php echo $log_description; ?></td>
|
||||
</tr>
|
||||
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue