all
Some checks failed
Publish Docker Image / build-and-push (push) Failing after 2m13s

This commit is contained in:
Sam Kintop
2026-04-30 09:44:02 -05:00
parent 0a30837e3d
commit bf3870ccca
111 changed files with 8383 additions and 0 deletions

53
src/Util/TimeInterval.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
namespace Aternos\Mclogs\Util;
class TimeInterval
{
use Singleton;
protected const array UNITS = [
"year" => 365 * 24 * 60 * 60,
"month" => 30 * 24 * 60 * 60,
"week" => 7 * 24 * 60 * 60,
"day" => 24 * 60 * 60,
"hour" => 60 * 60,
"minute" => 60,
"second" => 1,
];
/**
* @param int $value
* @param string $unit
* @return string
*/
protected function formatUnit(int $value, string $unit): string
{
if ($value === 1) {
return $value . " " . $unit;
} else {
return $value . " " . $unit . "s";
}
}
/**
* @param int $duration
* @param string $separator
* @return string
*/
public function format(int $duration, string $separator = ", "): string
{
$parts = [];
while ($duration > 0) {
foreach (self::UNITS as $unit => $seconds) {
if ($duration >= $seconds) {
$value = intdiv($duration, $seconds);
$duration -= $value * $seconds;
$parts[] = $this->formatUnit($value, $unit);
break;
}
}
}
return implode($separator, $parts);
}
}