diff options
author | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-05 22:27:48 -0500 |
---|---|---|
committer | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-05 22:27:48 -0500 |
commit | 544f9924241f9b2caaf83ead203161ea41e5f1cf (patch) | |
tree | dcb5ba8a202fee673e395184795f570fd7c905ae /vendor | |
parent | 1e994f34486da72662ff39f1c3e130e4480e30ab (diff) |
Add a 'due date' field and display the number of comments on the board
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/SimpleValidator/Validators/Date.php | 33 |
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; + } +} |