class DateComparator in Database Sanitize 7
DateCompare compiles date comparisons.
@author Fabien Potencier <fabien@symfony.com>
Hierarchy
- class \Symfony\Component\Finder\Comparator\Comparator
- class \Symfony\Component\Finder\Comparator\DateComparator
Expanded class hierarchy of DateComparator
4 files declare their use of DateComparator
- DateComparatorTest.php in vendor/
symfony/ finder/ Tests/ Comparator/ DateComparatorTest.php - DateRangeFilterIterator.php in vendor/
symfony/ finder/ Iterator/ DateRangeFilterIterator.php - DateRangeFilterIteratorTest.php in vendor/
symfony/ finder/ Tests/ Iterator/ DateRangeFilterIteratorTest.php - Finder.php in vendor/
symfony/ finder/ Finder.php
File
- vendor/
symfony/ finder/ Comparator/ DateComparator.php, line 19
Namespace
Symfony\Component\Finder\ComparatorView source
class DateComparator extends Comparator {
/**
* @param string $test A comparison string
*
* @throws \InvalidArgumentException If the test is not understood
*/
public function __construct($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 \DateTime($matches[2]);
$target = $date
->format('U');
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
}
$operator = isset($matches[1]) ? $matches[1] : '==';
if ('since' === $operator || 'after' === $operator) {
$operator = '>';
}
if ('until' === $operator || 'before' === $operator) {
$operator = '<';
}
$this
->setOperator($operator);
$this
->setTarget($target);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Comparator:: |
private | property | ||
Comparator:: |
private | property | ||
Comparator:: |
public | function | Gets the comparison operator. | |
Comparator:: |
public | function | Gets the target value. | |
Comparator:: |
public | function | Sets the comparison operator. | |
Comparator:: |
public | function | Sets the target value. | |
Comparator:: |
public | function | Tests against the target. | |
DateComparator:: |
public | function |