Skip to content

Commit

Permalink
Merge branch 'master' into 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 24, 2012
2 parents 3ee267d + 3729ac1 commit d201030
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
40 changes: 17 additions & 23 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -2242,9 +2242,9 @@ public function testInputTime() {
'type' => 'time', 'type' => 'time',
'selected' => '18:15' 'selected' => '18:15'
)); ));
$this->assertRegExp('#<option value="06"[^>]*>6</option>#', $result); $this->assertContains('<option value="06" selected="selected">6</option>', $result);
$this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result); $this->assertContains('<option value="15" selected="selected">15</option>', $result);
$this->assertRegExp('#<option value="pm"[^>]*>pm</option>#', $result); $this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
} }


/** /**
Expand All @@ -2253,6 +2253,15 @@ public function testInputTime() {
* @return void * @return void
*/ */
public function testTimeSelectedWithInterval() { public function testTimeSelectedWithInterval() {
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'interval' => 15,
'selected' => '2012-10-23 15:57:00'
));
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);

$result = $this->Form->input('Model.start_time', array( $result = $this->Form->input('Model.start_time', array(
'timeFormat' => 24, 'timeFormat' => 24,
'type' => 'time', 'type' => 'time',
Expand Down Expand Up @@ -5711,26 +5720,11 @@ public function testHour() {


$this->Form->request->data['Model']['field'] = ''; $this->Form->request->data['Model']['field'] = '';
$result = $this->Form->hour('Model.field', true, array('value' => '23')); $result = $this->Form->hour('Model.field', true, array('value' => '23'));
$expected = array( $this->assertContains('<option value="23" selected="selected">23</option>', $result);
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
array('option' => array('value' => '')), $result = $this->Form->hour('Model.field', false, array('value' => '23'));
'/option', $this->assertContains('<option value="11" selected="selected">11</option>', $result);
array('option' => array('value' => '00')),
'0',
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$hoursRegex,
array('option' => array('value' => '23', 'selected' => 'selected')),
'23',
'/option',
'/select',
);
$this->assertTags($result, $expected);


$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32'; $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
$result = $this->Form->hour('Model.field', true); $result = $this->Form->hour('Model.field', true);
Expand Down
10 changes: 6 additions & 4 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -2059,6 +2059,11 @@ public function hour($fieldName, $format24Hours = false, $attributes = array())
} elseif ($attributes['value'] === false) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
} }

if ($attributes['value'] > 12 && !$format24Hours) {
$attributes['value'] -= 12;
}

return $this->select( return $this->select(
$fieldName . ".hour", $fieldName . ".hour",
$this->_generateOptions($format24Hours ? 'hour24' : 'hour'), $this->_generateOptions($format24Hours ? 'hour24' : 'hour'),
Expand Down Expand Up @@ -2223,10 +2228,7 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a
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') {
$time[0] = $time[0] - 12;
$meridian = 'pm';
} elseif ($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;
Expand Down

0 comments on commit d201030

Please sign in to comment.