<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Services\Analyzators\Validators;

use DateTime;

/**
 * Class LexicalKontrolaDatum
 *
 * @package Seka\Portal\Modul\Statistiky\Services\Analyzators\Validators
 */
final class LexicalKontrolaDatum extends Lexical
{
    /**
     * @var string
     */
    private string $dateFormat = 'd.m.Y';

    /**
     * @param $input
     *
     * @return bool
     */
    public function validate($input): bool
    {
        parent::validate($input);

        return strlen($input) > 0 && DateTime::createFromFormat($this->dateFormat, $input) !== false;
    }

    /**
     * @param $input
     *
     * @return string
     */
    public function getErrorMsg($input): string
    {
        return sprintf('povoleny format: %s, %s', $this->dateFormat, $input);
    }
}
