Permalink
Browse files

Merge branch 'hotfix/3328' into develop

Forward port #3328
  • Loading branch information...
2 parents f684a12 + 18c5581 commit 6cc009b37750d0a555fd97b5fa8eb0c741fd65f0 @weierophinney weierophinney committed Jan 2, 2013
@@ -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;
@@ -40,32 +41,23 @@ 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"),
));
}
}
@@ -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"),
));
@@ -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;
@@ -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
@@ -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"),
));
}
}
@@ -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;
@@ -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 6cc009b

Please sign in to comment.