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

Commit

Permalink
Merge branch 'hotfix/3328'
Browse files Browse the repository at this point in the history
Close #3328
Close #3269
Fix #3195
  • Loading branch information
weierophinney committed Jan 2, 2013
2 parents 236c092 + 38a3cfe commit b5c2a47
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
18 changes: 5 additions & 13 deletions library/Zend/Form/Element/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Form\Element;

use DateInterval;
use Zend\Form\Element;
use Zend\Form\Element\DateTime as DateTimeElement;
use Zend\Validator\Date as DateValidator;
Expand Down Expand Up @@ -39,33 +40,24 @@ class Date extends DateTimeElement
*/
protected $format = 'Y-m-d';

/**
* Retrieves a Date Validator configured for a DateTime Input type
*
* @return \Zend\Validator\ValidatorInterface
*/
protected function getDateValidator()
{
return new DateValidator(array('format' => 'Y-m-d'));
}

/**
* Retrieves a DateStep Validator configured for a Date Input type
*
* @return \Zend\Validator\ValidatorInterface
*/
protected function getStepValidator()
{
$format = $this->getFormat();
$stepValue = (isset($this->attributes['step']))
? $this->attributes['step'] : 1; // Days

$baseValue = (isset($this->attributes['min']))
? $this->attributes['min'] : '1970-01-01';
? $this->attributes['min'] : date($format, 0);

return new DateStepValidator(array(
'format' => 'Y-m-d',
'format' => $format,
'baseValue' => $baseValue,
'step' => new \DateInterval("P{$stepValue}D"),
'step' => new DateInterval("P{$stepValue}D"),
));
}
}
5 changes: 3 additions & 2 deletions library/Zend/Form/Element/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ protected function getDateValidator()
*/
protected function getStepValidator()
{
$format = $this->getFormat();
$stepValue = (isset($this->attributes['step']))
? $this->attributes['step'] : 1; // Minutes

$baseValue = (isset($this->attributes['min']))
? $this->attributes['min'] : '1970-01-01T00:00Z';
? $this->attributes['min'] : date($format, 0);

return new DateStepValidator(array(
'format' => $this->format,
'format' => $format,
'baseValue' => $baseValue,
'step' => new DateInterval("PT{$stepValue}M"),
));
Expand Down
18 changes: 8 additions & 10 deletions library/Zend/Form/Element/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Form\Element;

use DateInterval;
use Zend\Form\Element;
use Zend\Validator\Date as DateValidator;
use Zend\Validator\DateStep as DateStepValidator;
Expand All @@ -31,14 +32,10 @@ class Time extends DateTime
);

/**
* Retrieves a Date Validator configured for a DateTime Input type
*
* @return \Zend\Validator\ValidatorInterface
* Default date format
* @var string
*/
protected function getDateValidator()
{
return new DateValidator(array('format' => 'H:i:s'));
}
protected $format = 'H:i:s';

/**
* Retrieves a DateStepValidator configured for a Date Input type
Expand All @@ -47,16 +44,17 @@ protected function getDateValidator()
*/
protected function getStepValidator()
{
$format = $this->getFormat();
$stepValue = (isset($this->attributes['step']))
? $this->attributes['step'] : 60; // Seconds

$baseValue = (isset($this->attributes['min']))
? $this->attributes['min'] : '00:00:00';
? $this->attributes['min'] : date($format, 0);

return new DateStepValidator(array(
'format' => 'H:i:s',
'format' => $format,
'baseValue' => $baseValue,
'step' => new \DateInterval("PT{$stepValue}S"),
'step' => new DateInterval("PT{$stepValue}S"),
));
}
}
22 changes: 21 additions & 1 deletion tests/ZendTest/Form/Element/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testProvidesDefaultInputSpecification()
case 'Zend\Validator\DateStep':
$dateInterval = new \DateInterval('P1D');
$this->assertEquals($dateInterval, $validator->getStep());
$this->assertEquals('1970-01-01', $validator->getBaseValue());
$this->assertEquals(date('Y-m-d', 0), $validator->getBaseValue());
break;
default:
break;
Expand Down Expand Up @@ -94,4 +94,24 @@ public function testValueReturnedFromComposedDateTimeIsRfc3339FullDateFormat()
$value = $element->getValue();
$this->assertEquals($date->format('Y-m-d'), $value);
}

public function testCorrectFormatPassedToDateValidator()
{
$element = new DateElement('foo');
$element->setAttributes(array(
'min' => '2012-01-01',
'max' => '2012-12-31',
));
$element->setFormat('d-m-Y');

$inputSpec = $element->getInputSpecification();
foreach ($inputSpec['validators'] as $validator) {
switch (get_class($validator)) {
case 'Zend\Validator\DateStep':
case 'Zend\Validator\Date':
$this->assertEquals('d-m-Y', $validator->getFormat());
break;
}
}
}
}

0 comments on commit b5c2a47

Please sign in to comment.