Merge branch 'phantom-master'

Refs GH-1182
This commit is contained in:
mark_story 2013-03-18 21:40:14 -04:00
commit b821505014
2 changed files with 32 additions and 4 deletions

View file

@ -2276,6 +2276,33 @@ class FormHelperTest extends CakeTestCase {
$this->assertContains('<option value="00" selected="selected">00</option>', $result); $this->assertContains('<option value="00" selected="selected">00</option>', $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('<option value="04" selected="selected">4</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 5,
'selected' => '2013-04-19 16:30:00'
));
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
}
/** /**
* test form->input() with datetime, date and time types * test form->input() with datetime, date and time types
* *

View file

@ -2387,7 +2387,8 @@ class FormHelper extends AppHelper {
} }
$change = (round($min * (1 / $interval)) * $interval) - $min; $change = (round($min * (1 / $interval)) * $interval) - $min;
$current->modify($change > 0 ? "+$change minutes" : "$change minutes"); $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; list($year, $month, $day, $hour, $min, $meridian) = $newTime;
} }
@ -2507,14 +2508,14 @@ class FormHelper extends AppHelper {
if (!empty($timeFormat)) { if (!empty($timeFormat)) {
$time = explode(':', $days[1]); $time = explode(':', $days[1]);
if ($time[0] >= '12' && $timeFormat === '12') { if ($time[0] >= 12 && $timeFormat == 12) {
$meridian = 'pm'; $meridian = 'pm';
} elseif ($time[0] === '00' && $timeFormat === '12') { } elseif ($time[0] === '00' && $timeFormat == 12) {
$time[0] = 12; $time[0] = 12;
} elseif ($time[0] >= 12) { } elseif ($time[0] >= 12) {
$meridian = 'pm'; $meridian = 'pm';
} }
if ($time[0] == 0 && $timeFormat === '12') { if ($time[0] == 0 && $timeFormat == 12) {
$time[0] = 12; $time[0] = 12;
} }
$hour = $min = null; $hour = $min = null;