ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DateComparator.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
5
12{
17 public function __construct(string $test)
18 {
19 if (!preg_match('#^\s*(==|!=|[<>]=?|after|since|before|until)?\s*(.+?)\s*$#i', $test, $matches)) {
20 throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
21 }
22
23 try {
24 $date = new \DateTime($matches[2]);
25 $target = $date->format('U');
26 } catch (\Exception $e) {
27 throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
28 }
29
30 $operator = $matches[1] ?? '==';
31
32 if ('since' === $operator || 'after' === $operator) {
33 $operator = '>';
34 }
35
36 if ('until' === $operator || 'before' === $operator) {
37 $operator = '<';
38 }
39
40 $this->setOperator($operator);
41 $this->setTarget($target);
42 }
43}
$test
Definition: Utf8Test.php:84
An exception for terminatinating execution or to throw for unit testing.
__construct(string $test)
DateComparator constructor.