Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2717' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
37 changes: 2 additions & 35 deletions src/DateStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@
* @category Zend
* @package Zend_Validate
*/
class DateStep extends AbstractValidator
class DateStep extends Date
{
const INVALID = 'dateStepInvalid';
const INVALID_DATE = 'dateStepInvalidDate';
const NOT_STEP = 'dateStepNotStep';

/**
* @var array
*/
protected $messageTemplates = array(
self::INVALID => "Invalid type given. String, integer, array or DateTime expected",
self::INVALID_DATE => "The input does not appear to be a valid date",
self::NOT_STEP => "The input is not a valid step"
);

Expand Down Expand Up @@ -155,28 +151,6 @@ public function getStep()
return $this->step;
}

/**
* Returns the format option
*
* @return string
*/
public function getFormat()
{
return $this->format;
}

/**
* Sets the format option
*
* @param string $format
* @return DateStep
*/
public function setFormat($format)
{
$this->format = $format;
return $this;
}

/**
* Returns the timezone option
*
Expand Down Expand Up @@ -241,13 +215,7 @@ protected function convertToDateTime($param)
*/
public function isValid($value)
{
if (!is_string($value)
&& !is_int($value)
&& !($value instanceof DateTime)
) {
$this->error(self::INVALID);
return false;
}
parent::isValid($value);

$this->setValue($value);

Expand All @@ -258,7 +226,6 @@ public function isValid($value)
try {
$valueDate = $this->convertToDateTime($value);
} catch (Exception\InvalidArgumentException $ex) {
$this->error(self::INVALID_DATE);
return false;
}

Expand Down
11 changes: 11 additions & 0 deletions test/DateStepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,15 @@ public function testEqualsMessageTemplates()
$this->assertObjectHasAttribute('messageTemplates', $validator);
$this->assertAttributeEquals($validator->getOption('messageTemplates'), 'messageTemplates', $validator);
}

public function testStepError()
{
$validator = new Validator\DateStep(array(
'format' => 'Y-m-d',
'baseValue' => '2012-01-23',
'step' => new DateInterval("P10D"),
));

$this->assertFalse($validator->isValid('2012-13-13'));
}
}

0 comments on commit 45610eb

Please sign in to comment.