Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DateComparator.php

class DateComparator

DateCompare compiles date comparisons.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\Finder\Comparator\Comparator
    • class \Symfony\Component\Finder\Comparator\DateComparator extends \Symfony\Component\Finder\Comparator\Comparator

Expanded class hierarchy of DateComparator

2 files declare their use of DateComparator
DateRangeFilterIterator.php in vendor/symfony/finder/Iterator/DateRangeFilterIterator.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(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);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Comparator::$operator private property
Comparator::getOperator public function Gets the comparison operator.
Comparator::getTarget public function Gets the target value.
Comparator::test public function Tests against the target.
DateComparator::__construct public function Overrides Comparator::__construct

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal