diff --git a/system/functions.php b/system/functions.php index 88c02102..ca7989ed 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1728,6 +1728,43 @@ function isCanary(): bool return isset($vipSystemEnabled); } +function getStatusUptimeReadable(int $uptime): string +{ + $fullMinute = 60; + $fullHour = (60 * $fullMinute); + $fullDay = (24 * $fullHour); + $fullMonth = (30 * $fullDay); + $fullYear = (365 * $fullDay); + + // years + $years = floor($uptime / $fullYear); + $y = ($years > 1 ? "$years years, " : ($years == 1 ? 'year, ' : '')); + + $uptime -= $years * $fullYear; + + // months + $months = floor($uptime / $fullMonth); + $m = ($months > 1 ? "$months months, " : ($months == 1 ? 'month, ' : '')); + + $uptime -= $months * $fullMonth; + + // days + $days = floor($uptime / $fullDay); + $d = ($days > 1 ? "$days days, " : ($days == 1 ? 'day, ' : '')); + + $uptime -= $days * $fullDay; + + // hours + $hours = floor($uptime / $fullHour); + + $uptime -= $hours * $fullHour; + + // minutes + $min = floor($uptime / $fullMinute); + + return "{$y}{$m}{$d}{$hours}h {$min}m"; +} + // validator functions require_once SYSTEM . 'compat/base.php'; diff --git a/system/status.php b/system/status.php index 8e8225dd..b69e7acc 100644 --- a/system/status.php +++ b/system/status.php @@ -145,13 +145,7 @@ function updateStatus() { } $uptime = $status['uptime'] = $serverStatus->getUptime(); - $m = date('m', $uptime); - $m = $m > 1 ? "$m months, " : ($m == 1 ? 'month, ' : ''); - $d = date('d', $uptime); - $d = $d > 1 ? "$d days, " : ($d == 1 ? 'day, ' : ''); - $h = date('H', $uptime); - $min = date('i', $uptime); - $status['uptimeReadable'] = "{$m}{$d}{$h}h {$min}m"; + $status['uptimeReadable'] = getStatusUptimeReadable($uptime); $status['monsters'] = $serverStatus->getMonstersCount(); $status['motd'] = $serverStatus->getMOTD();