2010-09-27 23:02:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2010-12-03 01:23:02 +01:00
|
|
|
use DateTime;
|
2010-09-27 23:02:30 +02:00
|
|
|
|
2010-12-03 01:23:02 +01:00
|
|
|
class Date extends AbstractRule
|
2010-09-27 23:02:30 +02:00
|
|
|
{
|
2011-02-10 21:49:48 +01:00
|
|
|
|
|
|
|
public $format = null;
|
2010-12-03 01:23:02 +01:00
|
|
|
|
2010-09-27 23:02:30 +02:00
|
|
|
public function __construct($format=null)
|
|
|
|
{
|
|
|
|
$this->format = $format;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validate($input)
|
|
|
|
{
|
2010-10-18 06:26:02 +02:00
|
|
|
if ($input instanceof DateTime)
|
|
|
|
return true;
|
2011-02-20 17:59:53 +01:00
|
|
|
elseif (!is_string($input))
|
2010-10-18 07:05:37 +02:00
|
|
|
return false;
|
2011-02-20 17:59:53 +01:00
|
|
|
elseif (is_null($this->format))
|
|
|
|
return false !== strtotime($input);
|
2010-09-27 23:02:30 +02:00
|
|
|
else
|
2011-02-20 17:59:53 +01:00
|
|
|
return $input === date($this->format, strtotime($input));
|
2010-09-27 23:02:30 +02:00
|
|
|
}
|
2010-12-03 01:23:02 +01:00
|
|
|
|
2011-02-10 21:49:48 +01:00
|
|
|
}
|
2011-03-13 15:50:47 +01:00
|
|
|
|