Comparator.php
4 years ago
DateComparator.php
4 years ago
NumberComparator.php
4 years ago
index.php
3 years ago
DateComparator.php
28 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Finder\Comparator; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class DateComparator extends Comparator |
| 5 | { |
| 6 | public function __construct(string $test) |
| 7 | { |
| 8 | if (!\preg_match('#^\\s*(==|!=|[<>]=?|after|since|before|until)?\\s*(.+?)\\s*$#i', $test, $matches)) { |
| 9 | throw new \InvalidArgumentException(\sprintf('Don\'t understand "%s" as a date test.', $test)); |
| 10 | } |
| 11 | try { |
| 12 | $date = new \DateTime($matches[2]); |
| 13 | $target = $date->format('U'); |
| 14 | } catch (\Exception $e) { |
| 15 | throw new \InvalidArgumentException(\sprintf('"%s" is not a valid date.', $matches[2])); |
| 16 | } |
| 17 | $operator = $matches[1] ?? '=='; |
| 18 | if ('since' === $operator || 'after' === $operator) { |
| 19 | $operator = '>'; |
| 20 | } |
| 21 | if ('until' === $operator || 'before' === $operator) { |
| 22 | $operator = '<'; |
| 23 | } |
| 24 | $this->setOperator($operator); |
| 25 | $this->setTarget($target); |
| 26 | } |
| 27 | } |
| 28 |