39 lines
891 B
PHP
39 lines
891 B
PHP
<?php
|
|
|
|
/**
|
|
* Проверка формата времени
|
|
*/
|
|
namespace ctiso\Validator\Rule;
|
|
use ctiso\Validator\Rule\AbstractRule,
|
|
ctiso\Collection;
|
|
|
|
class Time extends AbstractRule
|
|
{
|
|
/** @var non-empty-string */
|
|
private string $split = ":";
|
|
|
|
public function getErrorMsg(): string
|
|
{
|
|
return "Неверный формат времени";
|
|
}
|
|
|
|
static function checktime(int $hour, int $minute): bool
|
|
{
|
|
if ($hour > -1 && $hour < 24 && $minute > -1 && $minute < 60) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function isValid(Collection $container, $status = null): bool
|
|
{
|
|
/** @var list<string> */
|
|
$tmp = explode($this->split, $container->get($this->field), 2);
|
|
if (self::checktime ((int)$tmp[0], (int)$tmp[1])) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|