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

Commit

Permalink
Merge branch 'form-validators' of https://github.com/bakura10/zf2 int…
Browse files Browse the repository at this point in the history
…o hotfix/form-validator-cleanup
  • Loading branch information
weierophinney committed Jun 30, 2012
15 parents 09e43af + 066eb37 + 3569d8b + 00def10 + ecae47b + 0e552a5 + 4f854c2 + 2b17650 + c1c0447 + 73b1f80 + dd4a335 + a40eb42 + 9262db1 + bdbd950 + a264b09 commit f112e0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/DateStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DateStep extends AbstractValidator
*
* @var DateInterval
*/
protected $stepInterval;
protected $step;

/**
* Format to use for parsing date strings
Expand Down Expand Up @@ -92,7 +92,7 @@ public function __construct($options = array())
$options = func_get_args();
$temp['baseValue'] = array_shift($options);
if (!empty($options)) {
$temp['stepInterval'] = array_shift($options);
$temp['step'] = array_shift($options);
}
if (!empty($options)) {
$temp['format'] = array_shift($options);
Expand All @@ -107,10 +107,10 @@ public function __construct($options = array())
if (isset($options['baseValue'])) {
$this->setBaseValue($options['baseValue']);
}
if (isset($options['stepInterval'])) {
$this->setStepInterval($options['stepInterval']);
if (isset($options['step'])) {
$this->setStep($options['step']);
} else {
$this->setStepInterval(new DateInterval('P1D'));
$this->setStep(new DateInterval('P1D'));
}
if (array_key_exists('format', $options)) {
$this->setFormat($options['format']);
Expand Down Expand Up @@ -149,12 +149,12 @@ public function getBaseValue()
/**
* Sets the step date interval
*
* @param DateInterval $stepValue
* @param DateInterval $step
* @return DateStep
*/
public function setStepInterval(DateInterval $stepInterval)
public function setStep(DateInterval $step)
{
$this->stepInterval = $stepInterval;
$this->step = $step;
return $this;
}

Expand All @@ -163,9 +163,9 @@ public function setStepInterval(DateInterval $stepInterval)
*
* @return DateInterval
*/
public function getStepInterval()
public function getStep()
{
return $this->stepInterval;
return $this->step;
}

/**
Expand Down Expand Up @@ -265,7 +265,7 @@ public function isValid($value)
$this->setValue($value);

$baseDate = $this->convertToDateTime($this->getBaseValue());
$stepInterval = $this->getStepInterval();
$step = $this->getStep();

// Parse the date
try {
Expand All @@ -282,7 +282,7 @@ public function isValid($value)

// Optimization for simple intervals.
// Handle intervals of just one date or time unit.
$intervalParts = explode('|', $stepInterval->format('%y|%m|%d|%h|%i|%s'));
$intervalParts = explode('|', $step->format('%y|%m|%d|%h|%i|%s'));
$partCounts = array_count_values($intervalParts);
if (5 === $partCounts["0"]) {
// Find the unit with the non-zero interval
Expand Down Expand Up @@ -398,14 +398,14 @@ public function isValid($value)
// or until the value is exceeded.
if ($baseDate < $valueDate) {
while ($baseDate < $valueDate) {
$baseDate->add($stepInterval);
$baseDate->add($step);
if ($baseDate == $valueDate) {
return true;
}
}
} else {
while ($baseDate > $valueDate) {
$baseDate->sub($stepInterval);
$baseDate->sub($step);
if ($baseDate == $valueDate) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion test/DateStepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testDateStepValidation($interval, $format, $baseValue, $value, $
$validator = new Validator\DateStep(array(
'format' => $format,
'baseValue' => $baseValue,
'stepInterval' => new DateInterval($interval),
'step' => new DateInterval($interval),
));

$this->assertEquals($isValid, $validator->isValid($value));
Expand Down

0 comments on commit f112e0c

Please sign in to comment.