Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update minute() method to use datetime widget.

  • Loading branch information...
commit 1dbe9f7dc4cc8cc39b3c8e46849b73ab4a5ccd8d 1 parent abecb49
@markstory markstory authored
View
34 src/View/Helper/FormHelper.php
@@ -1992,35 +1992,25 @@ public function hour($fieldName, $options = []) {
* - `empty` - If true, the empty select option is shown. If a string,
* that string is displayed as the empty element.
* - `value` The selected value of the input.
+ * - `interval` The interval that minute options should be created at.
+ * - `round` How you want the value rounded when it does not fit neatly into an
+ * interval. Accepts 'up', 'down', and null.
*
* @param string $fieldName Prefix name for the SELECT element
- * @param array $attributes Array of Attributes
+ * @param array $options Array of options.
* @return string Completed minute select input.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::minute
*/
- public function minute($fieldName, $attributes = array()) {
- $attributes += array('empty' => true, 'value' => null);
- $attributes = $this->_dateTimeSelected('min', $fieldName, $attributes);
-
- if (strlen($attributes['value']) > 2) {
- $date = date_create($attributes['value']);
- $attributes['value'] = null;
- if ($date) {
- $attributes['value'] = $date->format('i');
- }
- } elseif ($attributes['value'] === false) {
- $attributes['value'] = null;
- }
- $minuteOptions = array();
+ public function minute($fieldName, $options = []) {
+ $options = $this->_singleDatetime($options, 'minute');
- if (isset($attributes['interval'])) {
- $minuteOptions['interval'] = $attributes['interval'];
- unset($attributes['interval']);
+ if (isset($options['val']) && $options['val'] > 0 && $options['val'] <= 60) {
+ $options['val'] = [
+ 'hour' => date('H'),
+ 'minute' => (int)$options['val'],
+ ];
}
- return $this->select(
- $fieldName . ".min", $this->_generateOptions('minute', $minuteOptions),
- $attributes
- );
+ return $this->datetime($fieldName, $options);
}
/**
View
14 tests/TestCase/View/Helper/FormHelperTest.php
@@ -5602,10 +5602,10 @@ public function testDay() {
public function testMinute() {
extract($this->dateRegex);
- $result = $this->Form->minute('Model.field');
+ $result = $this->Form->minute('Model.field', ['value' => '']);
$expected = array(
- array('select' => array('name' => 'Model[field][min]')),
- array('option' => array('value' => '')),
+ array('select' => array('name' => 'Model[field][minute]')),
+ array('option' => array('selected' => 'selected', 'value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
@@ -5624,7 +5624,7 @@ public function testMinute() {
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
$result = $this->Form->minute('Model.field');
$expected = array(
- array('select' => array('name' => 'Model[field][min]')),
+ array('select' => array('name' => 'Model[field][minute]')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
@@ -5648,8 +5648,8 @@ public function testMinute() {
$this->Form->request->data['Model']['field'] = '';
$result = $this->Form->minute('Model.field', array('interval' => 5));
$expected = array(
- array('select' => array('name' => 'Model[field][min]')),
- array('option' => array('value' => '')),
+ array('select' => array('name' => 'Model[field][minute]')),
+ array('option' => array('selected' => 'selected', 'value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
@@ -5668,7 +5668,7 @@ public function testMinute() {
$this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
$result = $this->Form->minute('Model.field', array('interval' => 5));
$expected = array(
- array('select' => array('name' => 'Model[field][min]')),
+ array('select' => array('name' => 'Model[field][minute]')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
Please sign in to comment.
Something went wrong with that request. Please try again.