Skip to content

Commit

Permalink
hour function + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcode authored and markstory committed Oct 30, 2010
1 parent 6620b3b commit 5f07003
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions cake/libs/view/helpers/form.php
Expand Up @@ -1617,14 +1617,13 @@ public function month($fieldName, $attributes = array()) {
*
* @param string $fieldName Prefix name for the SELECT element
* @param boolean $format24Hours True for 24 hours format
* @param string $selected Option which is selected.
* @param array $attributes List of HTML attributes
* @return string Completed hour select input
* @access public
* @link http://book.cakephp.org/view/1420/hour
*/
public function hour($fieldName, $format24Hours = false, $selected = null, $attributes = array()) {
$attributes += array('empty' => true, 'value' => $selected);
public function hour($fieldName, $format24Hours = false, $attributes = array()) {
$attributes += array('empty' => true, 'value' => null);
$attributes = $this->__dateTimeSelected('hour', $fieldName, $attributes);

if (strlen($attributes['value']) > 2) {
Expand Down Expand Up @@ -1901,12 +1900,14 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $s
}
$selectMinuteAttr['interval'] = $interval;
switch ($timeFormat) {
case '24':
$opt .= $this->hour($fieldName, true, $hour, $selectHourAttr) . ':' .
case '24':
$selectHourAttr['value'] = $hour;
$opt .= $this->hour($fieldName, true, $selectHourAttr) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr);
break;
case '12':
$opt .= $this->hour($fieldName, false, $hour, $selectHourAttr) . ':' .
case '12':
$selectHourAttr['value'] = $hour;
$opt .= $this->hour($fieldName, false, $selectHourAttr) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr) . ' ' .
$this->meridian($fieldName, $meridian, $selectMeridianAttr);
break;
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -4777,7 +4777,7 @@ function testHour() {
$this->assertTags($result, $expected);

$this->Form->request->data['Model']['field'] = '';
$result = $this->Form->hour('Model.field', true, '23');
$result = $this->Form->hour('Model.field', true, array('value' => '23'));
$expected = array(
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
array('option' => array('value' => '')),
Expand Down Expand Up @@ -4820,7 +4820,7 @@ function testHour() {
$this->assertTags($result, $expected);

unset($this->Form->request->data['Model']['field']);
$result = $this->Form->hour('Model.field', true, 'now');
$result = $this->Form->hour('Model.field', true, array('value' => 'now'));
$thisHour = date('H');
$optValue = date('G');
$this->assertPattern('/<option value="' . $thisHour . '" selected="selected">'. $optValue .'<\/option>/', $result);
Expand Down

0 comments on commit 5f07003

Please sign in to comment.