Feature branch PR for Spec 114. This branch contains the merged agent session work (see merge commit on branch). Tests - `vendor/bin/sail artisan test --compact tests/Feature/System/Spec114/` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #139
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\SystemConsole;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
|
|
final class SystemConsoleWindow
|
|
{
|
|
public const LastHour = '1h';
|
|
|
|
public const LastDay = '24h';
|
|
|
|
public const LastWeek = '7d';
|
|
|
|
private function __construct(
|
|
public readonly string $value,
|
|
private readonly int $minutes,
|
|
) {}
|
|
|
|
public static function fromNullable(?string $window): self
|
|
{
|
|
return match (trim((string) $window)) {
|
|
self::LastHour => new self(self::LastHour, 60),
|
|
self::LastWeek => new self(self::LastWeek, 10080),
|
|
default => new self(self::LastDay, 1440),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public static function options(): array
|
|
{
|
|
return [
|
|
self::LastHour => 'Last hour',
|
|
self::LastDay => 'Last 24 hours',
|
|
self::LastWeek => 'Last 7 days',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function allowed(): array
|
|
{
|
|
return array_keys(self::options());
|
|
}
|
|
|
|
public function startAt(?CarbonImmutable $now = null): CarbonImmutable
|
|
{
|
|
$now ??= CarbonImmutable::now();
|
|
|
|
return $now->subMinutes($this->minutes);
|
|
}
|
|
}
|