From ec56d828b0615e10aaf22e3bd07cf6cb80a88775 Mon Sep 17 00:00:00 2001 From: Graham Watson Date: Thu, 14 Mar 2013 16:48:12 -0300 Subject: [PATCH 1/5] Fix incorrect default meridian Prevent the default meridian from being changed from 'pm' to 'am' when the default time is in a 12-hour format between 1:00pm and 11:59pm and both a minute interval and default minute value are specified. --- lib/Cake/View/Helper/FormHelper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 0733cfd90..75cca4234 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2383,11 +2383,16 @@ class FormHelper extends AppHelper { $current->setDate($year, $month, $day); } if ($hour !== null) { + if ($timeFormat == '12') { + $hour = date('H', strtotime("$hour:$min $meridian")); + } $current->setTime($hour, $min); } $change = (round($min * (1 / $interval)) * $interval) - $min; $current->modify($change > 0 ? "+$change minutes" : "$change minutes"); $newTime = explode(' ', $current->format('Y m d H i a')); + $format = ($timeFormat == '12') ? 'Y m d h i a' : 'Y m d H i a'; + $newTime = explode(' ', $current->format($format)); list($year, $month, $day, $hour, $min, $meridian) = $newTime; } From 2ac545291af53f6e93a5fc2e7dbe900ba9d9ccb0 Mon Sep 17 00:00:00 2001 From: Graham Watson Date: Thu, 14 Mar 2013 16:58:13 -0300 Subject: [PATCH 2/5] Fix incorrect default meridian Forgot to remove a line --- lib/Cake/View/Helper/FormHelper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 75cca4234..ba3b3003c 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2390,7 +2390,6 @@ class FormHelper extends AppHelper { } $change = (round($min * (1 / $interval)) * $interval) - $min; $current->modify($change > 0 ? "+$change minutes" : "$change minutes"); - $newTime = explode(' ', $current->format('Y m d H i a')); $format = ($timeFormat == '12') ? 'Y m d h i a' : 'Y m d H i a'; $newTime = explode(' ', $current->format($format)); list($year, $month, $day, $hour, $min, $meridian) = $newTime; From e38892ff06c0066c572f8251953a091041246814 Mon Sep 17 00:00:00 2001 From: Graham Watson Date: Mon, 18 Mar 2013 13:34:14 -0300 Subject: [PATCH 3/5] Change equal operators to identity operators --- lib/Cake/View/Helper/FormHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index ba3b3003c..2bb2c54de 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2383,14 +2383,14 @@ class FormHelper extends AppHelper { $current->setDate($year, $month, $day); } if ($hour !== null) { - if ($timeFormat == '12') { + if ($timeFormat === '12') { $hour = date('H', strtotime("$hour:$min $meridian")); } $current->setTime($hour, $min); } $change = (round($min * (1 / $interval)) * $interval) - $min; $current->modify($change > 0 ? "+$change minutes" : "$change minutes"); - $format = ($timeFormat == '12') ? 'Y m d h i a' : 'Y m d H i a'; + $format = ($timeFormat === '12') ? 'Y m d h i a' : 'Y m d H i a'; $newTime = explode(' ', $current->format($format)); list($year, $month, $day, $hour, $min, $meridian) = $newTime; } From 37532389d670e4045072d20b6af5ef21b5df8aae Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 18 Mar 2013 21:37:38 -0400 Subject: [PATCH 4/5] Add test cases for GH-1182 Add tests for afternoon times with an interval and 12 hour time format. --- .../Test/Case/View/Helper/FormHelperTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index b95f21ce5..4988cd39f 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2276,6 +2276,33 @@ class FormHelperTest extends CakeTestCase { $this->assertContains('', $result); } +/** + * Test interval & timeFormat = 12 + * + * @return void + */ + public function testInputTimeWithIntervalAnd12HourFormat() { + $result = $this->Form->input('Model.start_time', array( + 'type' => 'time', + 'timeFormat' => 12, + 'interval' => 5, + 'selected' => array('hour' => '4', 'min' => '30', 'meridian' => 'pm') + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + + $result = $this->Form->input('Model.start_time', array( + 'type' => 'time', + 'timeFormat' => '12', + 'interval' => 5, + 'selected' => '2013-04-19 16:30:00' + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + } + /** * test form->input() with datetime, date and time types * From 2f799961404ed7fda48fbdbca15df08d15a86f0b Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 18 Mar 2013 21:38:02 -0400 Subject: [PATCH 5/5] Remove unused code and remove strict type checks. Remove some unused code around manipulating hours. Also allow the timeFormat option to be specified as either a string or an int. Both types should be accepted and treated as equivalent. --- lib/Cake/View/Helper/FormHelper.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 2bb2c54de..e7374a40f 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2383,9 +2383,6 @@ class FormHelper extends AppHelper { $current->setDate($year, $month, $day); } if ($hour !== null) { - if ($timeFormat === '12') { - $hour = date('H', strtotime("$hour:$min $meridian")); - } $current->setTime($hour, $min); } $change = (round($min * (1 / $interval)) * $interval) - $min; @@ -2511,14 +2508,14 @@ class FormHelper extends AppHelper { if (!empty($timeFormat)) { $time = explode(':', $days[1]); - if ($time[0] >= '12' && $timeFormat === '12') { + if ($time[0] >= 12 && $timeFormat == 12) { $meridian = 'pm'; - } elseif ($time[0] === '00' && $timeFormat === '12') { + } elseif ($time[0] === '00' && $timeFormat == 12) { $time[0] = 12; } elseif ($time[0] >= 12) { $meridian = 'pm'; } - if ($time[0] == 0 && $timeFormat === '12') { + if ($time[0] == 0 && $timeFormat == 12) { $time[0] = 12; } $hour = $min = null;