This commit is contained in:
William 2023-01-28 18:40:48 +01:00
parent 195d72b0f3
commit 983af52653
1 changed files with 21 additions and 1 deletions

View File

@ -1,3 +1,23 @@
<?php
function get_time_ago_human($time) {
$time = time() - $time;
$time = ($time<1)? 1 : $time;
$tokens = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -27,7 +47,7 @@
<?php foreach($messages as $message): ?>
<div>
<small><span style="color: yellow"><?=htmlspecialchars($message['nick'])?></span> <?=gmdate("D M j G:i:s Y", $message['date']);?></small>
<small><span style="color: yellow"><?=htmlspecialchars($message['nick'])?></span> <?=get_time_ago_human($message['date']) . ' ago'//gmdate("D M j G:i:s Y", $message['date']);?></small>
<p><?=htmlspecialchars($message['text'])?></p>
</div>
<?php endforeach; ?>