Permalink
Browse files

[#3328][#3269] Ensure date format is used consistently

- Removed getDateValidator() from all date/time element implementations
- Ensured $format is present on all date/time element implementations
- Use $format when creating step validators
  • Loading branch information...
1 parent 6d7d5e4 commit 18c5581563cac3909975b490662baf1b22a537ff @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;
@@ -46,16 +47,17 @@ class Date extends DateTimeElement
*/
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' => $this->getFormat(),
+ '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;

0 comments on commit 18c5581

Please sign in to comment.