Skip to content

Commit

Permalink
Update meridian() to use datetime widget class.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 25, 2014
1 parent 1dbe9f7 commit decbef7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
37 changes: 9 additions & 28 deletions src/View/Helper/FormHelper.php
Expand Up @@ -2048,39 +2048,20 @@ protected function _dateTimeSelected($select, $fieldName, $attributes) {
* - `value` The selected value of the input.
*
* @param string $fieldName Prefix name for the SELECT element
* @param array $attributes Array of Attributes
* @param array $options Array of options
* @return string Completed meridian select input
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::meridian
*/
public function meridian($fieldName, $attributes = array()) {
$attributes += array('empty' => true, 'value' => null);
if ((empty($attributes['value']) || $attributes['value'] === true) && $value = $this->value($fieldName)) {
if (is_array($value)) {
$meridian = null;
extract($value);
$attributes['value'] = $meridian;
} else {
if (empty($value)) {
if (!$attributes['empty']) {
$attributes['value'] = date('a');
}
} else {
$date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
$attributes['value'] = $date->format('a');
}
}
}
}
public function meridian($fieldName, $options = array()) {
$options = $this->_singleDatetime($options, 'meridian');

if ($attributes['value'] === false) {
$attributes['value'] = null;
if (isset($options['val'])) {
$options['val'] = [
'hour' => date('H'),
'minute' => (int)$options['val'],
];
}
return $this->select(
$fieldName . ".meridian", $this->_generateOptions('meridian'),
$attributes
);
return $this->datetime($fieldName, $options);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -5686,6 +5686,29 @@ public function testMinute() {
$this->assertTags($result, $expected);
}

/**
* Test generating an input for the meridian.
*
* @return void
*/
public function testMeridian() {
extract($this->dateRegex);

$now = time();
$result = $this->Form->meridian('Model.field', ['value' => 'am']);
$expected = [
array('select' => array('name' => 'Model[field][meridian]')),
array('option' => array('value' => '')),
'/option',
$meridianRegex,
array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
date('a', $now),
'/option',
'*/select'
];
$this->assertTags($result, $expected);
}

/**
* testHour method
*
Expand Down

0 comments on commit decbef7

Please sign in to comment.