<commit_before><?php declare(strict_types=1);

namespace PAF\Common\Forms\Controls;

use Nette\Forms\Controls\TextInput;
use Nette\UnexpectedValueException;
use Nette\Utils\DateTime;
use Nette\Utils\Html;

class DateInput extends TextInput
{
    const FORMAT_DATE = "Y-m-d";
    const FORMAT_DATETIME = "Y-m-d H:i";

    protected $format;

    public function __construct(string $format, string $label = null)
    {
        parent::__construct($label);
        $this->setOption('type', 'datetime');

        $this->format = $format;
        $this->setRequired(false);
        $this->addRule([$this, 'validateDate'], 'invalid-date-format');
    }

    public function setDate(DateTime $value)
    {
        return $this->setValue($value->format($this->format));
    }

    /**
     * @param string|DateTime $value
     * @return static
     * @internal
     */
    public function setValue($value)
    {
        if ($value instanceof \DateTime) {
            $value = $value->format($this->format);
        }
        /** @noinspection PhpInternalEntityUsedInspection */
        parent::setValue($value);
        return $this;
    }

    public function getValue()
    {
        return DateTime::createFromFormat($this->format, parent::getValue());
    }<commit_msg>Prevent time from being included for date-only format<commit_after><?php declare(strict_types=1);

namespace PAF\Common\Forms\Controls;

use Nette\Forms\Controls\TextInput;
use Nette\UnexpectedValueException;
use Nette\Utils\DateTime;
use Nette\Utils\Html;

class DateInput extends TextInput
{
    const FORMAT_DATE = "Y-m-d";
    const FORMAT_DATETIME = "Y-m-d H:i";

    protected $format;

    public function __construct(string $format, string $label = null)
    {
        parent::__construct($label);
        $this->setOption('type', 'datetime');

        $this->format = $format;
        $this->setRequired(false);
        $this->addRule([$this, 'validateDate'], 'invalid-date-format');
    }

    public function setDate(DateTime $value)
    {
        return $this->setValue($value->format($this->format));
    }

    /**
     * @param string|DateTime $value
     * @return static
     * @internal
     */
    public function setValue($value)
    {
        if ($value instanceof \DateTime) {
            $value = $value->format($this->format);
        }
        /** @noinspection PhpInternalEntityUsedInspection */
        parent::setValue($value);
        return $this;
    }

    public function getValue()
    {
        $value = DateTime::createFromFormat($this->format, parent::getValue());
        if ($this->format === self::FORMAT_DATE) {
            $value->setTime(0, 0, 0);
        }

        return $value;
    }
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.0018552875695732839, 'mean_word_length': 2.7653631284916202, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1674648', 'n_tokens_mistral': 804, 'n_tokens_neox': 793, 'n_words': 161}