Bulk substitution across all PHP files in src/, build.php, worker.php, and web/frontend/. Updates composer.json's package name and PSR-4 autoload root accordingly. Casing matches the existing IndifferentKetchup\Codex package's namespace convention (capital K). Strictly a namespace rename. Aternos\Codex\* imports remain in place; those get re-pointed in a follow-up commit when the codex Composer dependency itself is swapped. Filename renames (docker/mclogs.ini, web/public/css/mclogs.css), README walk-through, env-var prefix changes, and visible-text branding land in subsequent commits.
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace IndifferentKetchup\Iblogs\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);
|
|
}
|
|
}
|