Skip to content

Commit bc6a795

Browse files
committed
Merge branch 'hotfix/2717'
Close zendframework#2717
2 parents 2d05c76 + d63d80a commit bc6a795

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

library/Zend/Validator/DateStep.php

+2-35
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@
2121
* @category Zend
2222
* @package Zend_Validate
2323
*/
24-
class DateStep extends AbstractValidator
24+
class DateStep extends Date
2525
{
26-
const INVALID = 'dateStepInvalid';
27-
const INVALID_DATE = 'dateStepInvalidDate';
2826
const NOT_STEP = 'dateStepNotStep';
2927

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

@@ -155,28 +151,6 @@ public function getStep()
155151
return $this->step;
156152
}
157153

158-
/**
159-
* Returns the format option
160-
*
161-
* @return string
162-
*/
163-
public function getFormat()
164-
{
165-
return $this->format;
166-
}
167-
168-
/**
169-
* Sets the format option
170-
*
171-
* @param string $format
172-
* @return DateStep
173-
*/
174-
public function setFormat($format)
175-
{
176-
$this->format = $format;
177-
return $this;
178-
}
179-
180154
/**
181155
* Returns the timezone option
182156
*
@@ -241,13 +215,7 @@ protected function convertToDateTime($param)
241215
*/
242216
public function isValid($value)
243217
{
244-
if (!is_string($value)
245-
&& !is_int($value)
246-
&& !($value instanceof DateTime)
247-
) {
248-
$this->error(self::INVALID);
249-
return false;
250-
}
218+
parent::isValid($value);
251219

252220
$this->setValue($value);
253221

@@ -258,7 +226,6 @@ public function isValid($value)
258226
try {
259227
$valueDate = $this->convertToDateTime($value);
260228
} catch (Exception\InvalidArgumentException $ex) {
261-
$this->error(self::INVALID_DATE);
262229
return false;
263230
}
264231

tests/ZendTest/Validator/DateStepTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,15 @@ public function testEqualsMessageTemplates()
110110
$this->assertObjectHasAttribute('messageTemplates', $validator);
111111
$this->assertAttributeEquals($validator->getOption('messageTemplates'), 'messageTemplates', $validator);
112112
}
113+
114+
public function testStepError()
115+
{
116+
$validator = new Validator\DateStep(array(
117+
'format' => 'Y-m-d',
118+
'baseValue' => '2012-01-23',
119+
'step' => new DateInterval("P10D"),
120+
));
121+
122+
$this->assertFalse($validator->isValid('2012-13-13'));
123+
}
113124
}

0 commit comments

Comments
 (0)