Add a 'due date' field and display the number of comments on the board
This commit is contained in:
33
vendor/SimpleValidator/Validators/Date.php
vendored
Normal file
33
vendor/SimpleValidator/Validators/Date.php
vendored
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user