ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DatetimeValidator.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
27{
28 use DataFetcher;
29
31
32 public function __construct(
34 ) {
35 $this->data_helper = $data_helper;
36 }
37
38 public function isValid(
39 ElementInterface $element,
40 bool $ignore_marker
41 ): bool {
42 $value = $this->dataValue($element, $ignore_marker);
43 if (!$this->data_helper->matchesDatetimePattern($value)) {
44 return false;
45 }
46
47 $matches = iterator_to_array($this->data_helper->datetimeToIterator($value));
48
49 if (isset($matches[0]) && ((int) $matches[0]) < 1) {
50 return false;
51 }
52 if (isset($matches[1]) &&
53 (((int) $matches[1]) < 1 || ((int) $matches[1]) > 12)) {
54 return false;
55 }
56 if (isset($matches[2]) &&
57 (((int) $matches[2]) < 1 || ((int) $matches[2]) > 31)) {
58 return false;
59 }
60 if (isset($matches[3]) && ((int) $matches[3]) > 23) {
61 return false;
62 }
63 if (isset($matches[4]) && ((int) $matches[4]) > 59) {
64 return false;
65 }
66 if (isset($matches[5]) && ((int) $matches[5]) > 59) {
67 return false;
68 }
69 return true;
70 }
71}
isValid(ElementInterface $element, bool $ignore_marker)