{"record":{"id":"fa2d1363a568545d","repo":"symfony/finder","slug":"s-is-not-a-valid-date","errorCode":null,"errorMessage":"\"%s\" is not a valid date.","messagePattern":"\"(.+?)\" is not a valid date\\.","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Comparator/DateComparator.php","lineNumber":36,"sourceCode":" */\nclass DateComparator extends Comparator\n{\n    /**\n     * @param string $test A comparison string\n     *\n     * @throws \\InvalidArgumentException If the test is not understood\n     */\n    public function __construct(string $test)\n    {\n        if (!preg_match('#^\\s*(==|!=|[<>]=?|after|since|before|until)?\\s*(.+?)\\s*$#i', $test, $matches)) {\n            throw new \\InvalidArgumentException(\\sprintf('Don\\'t understand \"%s\" as a date test.', $test));\n        }\n\n        try {\n            $date = new \\DateTimeImmutable($matches[2]);\n            $target = $date->format('U');\n        } catch (\\Exception) {\n            throw new \\InvalidArgumentException(\\sprintf('\"%s\" is not a valid date.', $matches[2]));\n        }\n\n        $operator = $matches[1] ?: '==';\n        if ('since' === $operator || 'after' === $operator) {\n            $operator = '>';\n        }\n\n        if ('until' === $operator || 'before' === $operator) {\n            $operator = '<';\n        }\n\n        parent::__construct($target, $operator);\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":51,"githubUrl":"https://github.com/symfony/finder/blob/4d6c057bfd67c5a93e8025c85ca9364cba7e260a/Comparator/DateComparator.php#L18-L51","documentation":"DateComparator successfully matched an operator prefix but new DateTimeImmutable($matches[2]) could not parse the remaining text, so it throws InvalidArgumentException declaring the string is not a valid date. The library relies on PHP's date parsing, so any unparseable date expression triggers this.","triggerScenarios":"new DateComparator('since someday') or Finder::date('> not-a-date') where the date portion (e.g. 'someday', 'next someday', typo like '2024-13-45') fails DateTimeImmutable parsing.","commonSituations":"Typos in relative date expressions ('yestreday'), locale-specific date strings not supported by PHP, passing human text like 'a week ago and a half', copy-pasted dates with stray characters.","solutions":["Use a date expression PHP DateTimeImmutable can parse: 'yesterday', '-7 days', '2024-01-01', 'since Monday'","Test the string first with new \\DateTimeImmutable($date) in a try/catch before building the comparator","Prefer absolute ISO dates (Y-m-d or ISO 8601) in configs to avoid relative-expression ambiguity"],"exampleFix":"// before\n$finder->date('since yestreday'); // unparseable\n// after\n$finder->date('since yesterday');","handlingStrategy":"validation","validationCode":"try { new \\DateTimeImmutable($datePart); } catch (\\Exception $e) { /* reject: not a valid date */ }","typeGuard":"function isParsableDate(string $s): bool { try { new \\DateTimeImmutable($s); return true; } catch (\\Exception) { return false; } }","tryCatchPattern":"try { $finder->date($test); } catch (\\InvalidArgumentException $e) { /* handle unparseable date */ }","preventionTips":["Pre-parse the date portion with DateTimeImmutable before building the comparator","Prefer absolute ISO 8601 dates in configs","Avoid locale-dependent or colloquial date phrases","Trim stray whitespace/characters from user input"],"tags":["dates","parsing","invalid-date"],"backgroundTag":"invalid-date-format","analyzedSha":"4d6c057bfd67c5a93e8025c85ca9364cba7e260a","analyzedAt":"2026-09-13T07:49:33.433Z","contentChangedAt":"2026-09-13T07:49:33.433Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}