mirror of
https://github.com/Respect/Validation.git
synced 2024-06-09 17:22:20 +02:00
Improve date and time handling on "Min" rule
This commit is contained in:
parent
9a5f4302cb
commit
e91d0ef22e
|
@ -7,12 +7,12 @@ class MinException extends ValidationException
|
|||
|
||||
public static $defaultTemplates = array(
|
||||
self::MODE_DEFAULT => array(
|
||||
self::STANDARD => '{{name}} must be greater than {{minValue}}',
|
||||
self::INCLUSIVE => '{{name}} must be greater than or equals {{minValue}}',
|
||||
self::STANDARD => '{{name}} must be greater than {{interval}}',
|
||||
self::INCLUSIVE => '{{name}} must be greater than or equals {{interval}}',
|
||||
),
|
||||
self::MODE_NEGATIVE => array(
|
||||
self::STANDARD => '{{name}} must not be greater than {{minValue}}',
|
||||
self::INCLUSIVE => '{{name}} must not be greater than or equals {{minValue}}',
|
||||
self::STANDARD => '{{name}} must not be greater than {{interval}}',
|
||||
self::INCLUSIVE => '{{name}} must not be greater than or equals {{interval}}',
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -1,23 +1,14 @@
|
|||
<?php
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class Min extends AbstractRule
|
||||
class Min extends AbstractInterval
|
||||
{
|
||||
public $inclusive;
|
||||
public $minValue;
|
||||
|
||||
public function __construct($minValue, $inclusive = false)
|
||||
{
|
||||
$this->minValue = $minValue;
|
||||
$this->inclusive = $inclusive;
|
||||
}
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
if ($this->inclusive) {
|
||||
return $input >= $this->minValue;
|
||||
} else {
|
||||
return $input > $this->minValue;
|
||||
return $this->filterInterval($input) >= $this->filterInterval($this->interval);
|
||||
}
|
||||
|
||||
return $this->filterInterval($input) > $this->filterInterval($this->interval);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class MinTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -35,6 +37,15 @@ class MinTest extends \PHPUnit_Framework_TestCase
|
|||
array(-100, false, 200),
|
||||
array(200, true, 200),
|
||||
array(200, false, 300),
|
||||
array('a', true, 'a'),
|
||||
array('a', true, 'c'),
|
||||
array('yesterday', true, 'now'),
|
||||
|
||||
// Samples from issue #178
|
||||
array('13-05-2014 03:16', true, '20-05-2014 03:16'),
|
||||
array(new DateTime('13-05-2014 03:16'), true, new DateTime('20-05-2014 03:16')),
|
||||
array('13-05-2014 03:16', true, new DateTime('20-05-2014 03:16')),
|
||||
array(new DateTime('13-05-2014 03:16'), true, '20-05-2014 03:16'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue