Expanded timeAgo function to incoude time ahead, added this functionality to client overview

This commit is contained in:
johnnyq
2024-01-15 22:59:39 -05:00
parent b5e67eb3f6
commit e07fb9ce50
2 changed files with 20 additions and 10 deletions

View File

@@ -681,12 +681,16 @@ function sanitizeForEmail($data) {
function timeAgo($datetime) {
$time = strtotime($datetime);
$difference = time() - $time;
$difference = $time - time(); // Changed to handle future dates
if ($difference < 1) {
return 'just now';
if ($difference == 0) {
return 'right now';
}
$timeRules = array (
$isFuture = $difference > 0; // Check if the date is in the future
$difference = abs($difference); // Absolute value for calculation
$timeRules = array(
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
@@ -700,7 +704,8 @@ function timeAgo($datetime) {
$div = $difference / $secs;
if ($div >= 1) {
$t = round($div);
return $t . ' ' . $str . ($t > 1 ? 's' : '') . ' ago';
$timeStr = $t . ' ' . $str . ($t > 1 ? 's' : '');
return $isFuture ? 'in ' . $timeStr : $timeStr . ' ago';
}
}
}