function DateComparator::__construct
Parameters
string $test A comparison string:
Throws
\InvalidArgumentException If the test is not understood
Overrides Comparator::__construct
File
-
vendor/
symfony/ finder/ Comparator/ DateComparator.php, line 26
Class
- DateComparator
- DateCompare compiles date comparisons.
Namespace
Symfony\Component\Finder\ComparatorCode
public function __construct(string $test) {
if (!preg_match('#^\\s*(==|!=|[<>]=?|after|since|before|until)?\\s*(.+?)\\s*$#i', $test, $matches)) {
throw new \InvalidArgumentException(\sprintf('Don\'t understand "%s" as a date test.', $test));
}
try {
$date = new \DateTimeImmutable($matches[2]);
$target = $date->format('U');
} catch (\Exception) {
throw new \InvalidArgumentException(\sprintf('"%s" is not a valid date.', $matches[2]));
}
$operator = $matches[1] ?? '==';
if ('since' === $operator || 'after' === $operator) {
$operator = '>';
}
if ('until' === $operator || 'before' === $operator) {
$operator = '<';
}
parent::__construct($target, $operator);
}