Working on temp ban system

This commit is contained in:
Michał Gdula 2022-09-15 15:40:12 +00:00
parent 76826e5e41
commit 6f39ca7759
6 changed files with 299 additions and 83 deletions

View file

@ -137,5 +137,35 @@ class Image {
return False;
}
}
}
class Diff {
function time($past_time, $full_date = false) {
$now = new \DateTime;
$ago = new \DateTime($past_time);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full_date) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
}