Nette\Utils\Finder::compare PHP Method

compare() public static method

Compares two values.
public static compare ( $l, $operator, $r ) : boolean
return boolean
    public static function compare($l, $operator, $r)
    {
        switch ($operator) {
            case '>':
                return $l > $r;
            case '>=':
                return $l >= $r;
            case '<':
                return $l < $r;
            case '<=':
                return $l <= $r;
            case '=':
            case '==':
                return $l == $r;
            case '!':
            case '!=':
            case '<>':
                return $l != $r;
            default:
                throw new Nette\InvalidArgumentException("Unknown operator {$operator}.");
        }
    }

Usage Example

 /**
  * Restricts the search by modified time.
  * @param  string  "[operator] [date]" example: >1978-01-23
  * @param  mixed
  * @return self
  */
 public function date($operator, $date = NULL)
 {
     if (func_num_args() === 1) {
         // in $operator is predicate
         if (!preg_match('#^(?:([=<>!]=?|<>)\\s*)?(.+)\\z#i', $operator, $matches)) {
             throw new Nette\InvalidArgumentException('Invalid date predicate format.');
         }
         list(, $operator, $date) = $matches;
         $operator = $operator ? $operator : '=';
     }
     $date = Nette\DateTime::from($date)->format('U');
     return $this->filter(function ($file) use($operator, $date) {
         return Finder::compare($file->getMTime(), $operator, $date);
     });
 }
All Usage Examples Of Nette\Utils\Finder::compare