interval_spec = $interval_spec; } public function validate($value, Constraint $constraint) { if (null === $value) { return; } if (!$value instanceof DateTime) { throw new LogicException('The input should a be a \DateTime interface,' . (is_object($value) ? get_class($value) : gettype($value))); } $limitDate = $this->getLimitDate(); if ($limitDate < $value) { $this->context->buildViolation($constraint->message) ->setParameter('%date%', $limitDate->format('d-m-Y')) ->setCode(Birthdate::BIRTHDATE_INVALID_CODE) ->addViolation(); } } /** * @return DateTime */ private function getLimitDate() { if (null !== $this->interval_spec) { $interval = new DateInterval($this->interval_spec); return (new DateTime('now'))->sub($interval); } return new DateTime('now'); } }