summaryrefslogtreecommitdiff
path: root/vendor/SimpleValidator/Validators/Date.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/SimpleValidator/Validators/Date.php')
-rw-r--r--vendor/SimpleValidator/Validators/Date.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/SimpleValidator/Validators/Date.php b/vendor/SimpleValidator/Validators/Date.php
new file mode 100644
index 00000000..36b59fbe
--- /dev/null
+++ b/vendor/SimpleValidator/Validators/Date.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace SimpleValidator\Validators;
+
+use SimpleValidator\Base;
+
+class Date extends Base
+{
+ private $format;
+
+ public function __construct($field, $error_message, $format)
+ {
+ parent::__construct($field, $error_message);
+ $this->format = $format;
+ }
+
+ public function execute(array $data)
+ {
+ if (isset($data[$this->field]) && $data[$this->field] !== '') {
+
+ $date = \DateTime::createFromFormat($this->format, $data[$this->field]);
+
+ if ($date !== false) {
+ $errors = \DateTime::getLastErrors();
+ return $errors['error_count'] === 0 && $errors['warning_count'] === 0;
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+}