1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Finder\Comparator;
13:
14: 15: 16: 17: 18:
19: class DateComparator extends Comparator
20: {
21:
22: 23: 24: 25: 26: 27: 28:
29: public function __construct($test)
30: {
31: if (!preg_match('#^\s*(==|!=|[<>]=?|after|since|before|until)?\s*(.+?)\s*$#i', $test, $matches)) {
32: throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
33: }
34:
35: try {
36: $date = new \DateTime($matches[2]);
37: $target = $date->format('U');
38: } catch (\Exception $e) {
39: throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
40: }
41:
42: $operator = isset($matches[1]) ? $matches[1] : '==';
43: if ('since' === $operator || 'after' === $operator) {
44: $operator = '>';
45: }
46:
47: if ('until' === $operator || 'before' === $operator) {
48: $operator = '<';
49: }
50:
51: $this->setOperator($operator);
52: $this->setTarget($target);
53: }
54: }
55: