You are here

class DateComparator in Database Sanitize 7

DateCompare compiles date comparisons.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

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\Comparator
View 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

Namesort descending Modifiers Type Description Overrides
Comparator::$operator private property
Comparator::$target private property
Comparator::getOperator public function Gets the comparison operator.
Comparator::getTarget public function Gets the target value.
Comparator::setOperator public function Sets the comparison operator.
Comparator::setTarget public function Sets the target value.
Comparator::test public function Tests against the target.
DateComparator::__construct public function