Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Form] [DateTimeSelect] Filter, manager, and view helper fixes #3722

Merged
merged 4 commits into from

2 participants

@radnan

The filter has been fixed for when the second is not provided.

The view helpers have been fixed with the correct ranges for the hour, minute, and second value options.

The DateTimeSelect element has been added to the FormElementManager service locator.

@weierophinney weierophinney was assigned
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3722' into develop
Forward port #3722
d18443c
@weierophinney weierophinney merged commit e1159d6 into zendframework:develop
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3722'
Close #3722
c302979
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3722'
Close #3722
8935d67
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3722' into develop
Forward port #3722
1006a9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  library/Zend/Form/Element/DateTimeSelect.php
@@ -291,6 +291,9 @@ public function getInputSpecification()
'callback' => function($date) {
// Convert the date to a specific format
if (is_array($date)) {
+ if (!isset($date['second'])) {
+ $date['second'] = '00';
+ }
$date = sprintf('%s-%s-%s %s:%s:%s',
$date['year'], $date['month'], $date['day'],
$date['hour'], $date['minute'], $date['second']
View
1  library/Zend/Form/FormElementManager.php
@@ -36,6 +36,7 @@ class FormElementManager extends AbstractPluginManager
'dateselect' => 'Zend\Form\Element\DateSelect',
'datetime' => 'Zend\Form\Element\DateTime',
'datetimelocal' => 'Zend\Form\Element\DateTimeLocal',
+ 'datetimeselect' => 'Zend\Form\Element\DateTimeSelect',
'element' => 'Zend\Form\Element',
'email' => 'Zend\Form\Element\Email',
'fieldset' => 'Zend\Form\Fieldset',
View
6 library/Zend/Form/View/Helper/FormDateTimeSelect.php
@@ -234,7 +234,7 @@ protected function getHoursOptions($pattern)
$date = new DateTime('1970-01-01 00:00:00');
$result = array();
- for ($hour = 1; $hour <= 31; $hour++) {
+ for ($hour = 1; $hour <= 24; $hour++) {
$key = $keyFormatter->format($date);
$value = $valueFormatter->format($date);
$result[$key] = $value;
@@ -258,7 +258,7 @@ protected function getMinutesOptions($pattern)
$date = new DateTime('1970-01-01 00:00:00');
$result = array();
- for ($hour = 1; $hour <= 31; $hour++) {
+ for ($min = 1; $min <= 60; $min++) {
$key = $keyFormatter->format($date);
$value = $valueFormatter->format($date);
$result[$key] = $value;
@@ -282,7 +282,7 @@ protected function getSecondsOptions($pattern)
$date = new DateTime('1970-01-01 00:00:00');
$result = array();
- for ($hour = 1; $hour <= 31; $hour++) {
+ for ($sec = 1; $sec <= 60; $sec++) {
$key = $keyFormatter->format($date);
$value = $valueFormatter->format($date);
$result[$key] = $value;
View
20 tests/ZendTest/Form/Element/DateTimeSelectTest.php
@@ -15,6 +15,7 @@
use Zend\Form\Element\DateTimeSelect as DateTimeSelectElement;
use Zend\Form\Factory;
use Zend\Form\Exception;
+use Zend\InputFilter\Factory as InputFilterFactory;
class DateTimeSelectTest extends TestCase
{
@@ -42,6 +43,25 @@ public function testProvidesInputSpecificationThatIncludesValidatorsBasedOnAttri
}
}
+ public function testInputSpecificationFilterIfSecondNotProvided()
+ {
+ $element = new DateTimeSelectElement('test');
+ $factory = new InputFilterFactory();
+ $inputFilter = $factory->createInputFilter(array(
+ 'test' => $element->getInputSpecification(),
+ ));
+ $inputFilter->setData(array(
+ 'test' => array(
+ 'year' => '2013',
+ 'month' => '02',
+ 'day' => '07',
+ 'hour' => '03',
+ 'minute' => '14'
+ ),
+ ));
+ $this->assertTrue($inputFilter->isValid());
+ }
+
public function testCanSetDateFromDateTime()
{
$element = new DateTimeSelectElement();
Something went wrong with that request. Please try again.