|
|
@ -15,14 +15,20 @@ class DateTimeValidator extends AbstractDateTimeValidator {
|
|
|
|
* @var bool Is the time part mandatory ?
|
|
|
|
* @var bool Is the time part mandatory ?
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private bool $timeMandatory;
|
|
|
|
private bool $timeMandatory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @var DateTimeInterface The time part (if not mandatory)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private DateTimeInterface $timePart;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a validator
|
|
|
|
* Create a validator
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param bool $mandatoryDate Is the time part mandatory ?
|
|
|
|
* @param bool $timeMandatory Is the time part mandatory ?
|
|
|
|
|
|
|
|
* @param DateTimeInterface|null $timePart The time part (if not mandatory)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __construct (bool $mandatoryDate = false) {
|
|
|
|
public function __construct (bool $timeMandatory = false, ?DateTimeInterface $timePart = null) {
|
|
|
|
$this->setTimeMandatory($mandatoryDate);
|
|
|
|
$this->setTimeMandatory($timeMandatory);
|
|
|
|
|
|
|
|
$this->setTimePart($timePart ?? (new DateTimeImmutable())->setTimestamp(0));
|
|
|
|
parent::__construct();
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -56,9 +62,9 @@ class DateTimeValidator extends AbstractDateTimeValidator {
|
|
|
|
(int)$this->getInternalValidator()->getMatch('day'),
|
|
|
|
(int)$this->getInternalValidator()->getMatch('day'),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
return $value->setTime(
|
|
|
|
return $value->setTime(
|
|
|
|
(int)($this->getInternalValidator()->getMatch('hour') ?? 0),
|
|
|
|
(int)($this->getInternalValidator()->getMatch('hour') ?? (int)$this->getTimePart()->format('%H')),
|
|
|
|
(int)($this->getInternalValidator()->getMatch('minute') ?? 0),
|
|
|
|
(int)($this->getInternalValidator()->getMatch('minute') ?? (int)$this->getTimePart()->format('%i')),
|
|
|
|
(int)($this->getInternalValidator()->getMatch('second') ?? 0),
|
|
|
|
(int)($this->getInternalValidator()->getMatch('second') ?? (int)$this->getTimePart()->format('%s')),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -81,4 +87,24 @@ class DateTimeValidator extends AbstractDateTimeValidator {
|
|
|
|
$this->timeMandatory = $timeMandatory;
|
|
|
|
$this->timeMandatory = $timeMandatory;
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* The time part (if not mandatory)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return DateTimeInterface The time part (if not mandatory)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getTimePart (): DateTimeInterface {
|
|
|
|
|
|
|
|
return $this->timePart;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Set the time part (if not mandatory)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param DateTimeInterface $timePart The time part
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setTimePart (DateTimeInterface $timePart): self {
|
|
|
|
|
|
|
|
$this->timePart = $timePart;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|