diff --git a/src/View/Widget/DateTime.php b/src/View/Widget/DateTime.php
index 967223e38e2..39d97cbf402 100644
--- a/src/View/Widget/DateTime.php
+++ b/src/View/Widget/DateTime.php
@@ -196,6 +196,13 @@ protected function _deconstructDate($value, $options) {
if (isset($value['year'], $value['month'], $value['day'])) {
$date->setDate($value['year'], $value['month'], $value['day']);
}
+ if (!isset($value['second'])) {
+ $value['second'] = 0;
+ }
+ if (isset($value['meridian'])) {
+ $isAm = strtolower($value['meridian']) === 'am';
+ $value['hour'] = $isAm ? $value['hour'] : $value['hour'] + 12;
+ }
if (isset($value['hour'], $value['minute'], $value['second'])) {
$date->setTime($value['hour'], $value['minute'], $value['second']);
}
diff --git a/tests/TestCase/View/Helper/FormHelperTest.php b/tests/TestCase/View/Helper/FormHelperTest.php
index d6a1001fb36..ad52799169a 100755
--- a/tests/TestCase/View/Helper/FormHelperTest.php
+++ b/tests/TestCase/View/Helper/FormHelperTest.php
@@ -5237,35 +5237,38 @@ public function testDatetimeMinuteInterval() {
extract($this->dateRegex);
$now = strtotime('now');
- $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'value' => ''));
+ $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array(
+ 'interval' => 5,
+ 'value' => ''
+ ));
$expected = array(
- array('select' => array('name' => 'Contact[date][day]')),
- $daysRegex,
- array('option' => array('value' => '')),
+ array('select' => array('name' => 'Contact[date][month]')),
+ $monthsRegex,
+ array('option' => array('selected' => 'selected', 'value' => '')),
'/option',
'*/select',
- array('select' => array('name' => 'Contact[date][month]')),
- $monthsRegex,
- array('option' => array('value' => '')),
+ array('select' => array('name' => 'Contact[date][day]')),
+ $daysRegex,
+ array('option' => array('selected' => 'selected', 'value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'Contact[date][year]')),
$yearsRegex,
- array('option' => array('value' => '')),
+ array('option' => array('selected' => 'selected', 'value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'Contact[date][hour]')),
$hoursRegex,
- array('option' => array('value' => '')),
+ array('option' => array('selected' => 'selected', 'value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'Contact[date][minute]')),
$minutesRegex,
- array('option' => array('value' => '')),
+ array('option' => array('selected' => 'selected', 'value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
@@ -5277,15 +5280,8 @@ public function testDatetimeMinuteInterval() {
'10',
'/option',
'*/select',
-
- array('select' => array('name' => 'Contact[date][meridian]')),
- $meridianRegex,
- array('option' => array('value' => '')),
- '/option',
- '*/select'
);
$this->assertTags($result, $expected);
- $this->assertNotRegExp('/', $result);
}
+/**
+ * Test that render() works with an array for val that is missing seconds.
+ *
+ * @return void
+ */
+ public function testRenderSelectedNoSeconds() {
+ $selected = [
+ 'year' => '2014', 'month' => '01', 'day' => '20',
+ 'hour' => '12', 'minute' => '30'
+ ];
+ $result = $this->DateTime->render(['val' => $selected]);
+ $this->assertContains('', $result);
+ $this->assertContains('', $result);
+ $this->assertContains('', $result);
+ $this->assertContains('', $result);
+ $this->assertContains('', $result);
+ }
+
+/**
+ * Test that render() adjusts hours based on meridian
+ *
+ * @return void
+ */
+ public function testRenderSelectedMeridian() {
+ $selected = [
+ 'year' => '2014', 'month' => '01', 'day' => '20',
+ 'hour' => '7', 'minute' => '30', 'meridian' => 'pm'
+ ];
+ $result = $this->DateTime->render(['val' => $selected]);
+ $this->assertContains('', $result);
+ $this->assertContains('', $result);
+ $this->assertContains('', $result);
+ $this->assertContains('', $result);
+ }
+
/**
* Test rendering widgets with empty values.
*