|
|
@@ -2343,6 +2343,7 @@ class FormHelper extends AppHelper {
|
|
|
* - `separator` The contents of the string between select elements. Defaults to '-'
|
|
|
* - `empty` - If true, the empty select option is shown. If a string,
|
|
|
* that string is displayed as the empty element.
|
|
|
+ * - `round` - Set to `up` or `down` if you want to force rounding in either direction. Defaults to null.
|
|
|
* - `value` | `default` The default value to be used by the input. A value in `$this->data`
|
|
|
* matching the field name will override this value. If no default is provided `time()` will be used.
|
|
|
*
|
|
|
@@ -2377,7 +2378,7 @@ class FormHelper extends AppHelper {
|
|
|
|
|
|
$defaults = array(
|
|
|
'minYear' => null, 'maxYear' => null, 'separator' => '-',
|
|
|
- 'interval' => 1, 'monthNames' => true
|
|
|
+ 'interval' => 1, 'monthNames' => true, 'round' => null
|
|
|
);
|
|
|
$attributes = array_merge($defaults, (array)$attributes);
|
|
|
if (isset($attributes['minuteInterval'])) {
|
|
|
@@ -2389,6 +2390,7 @@ class FormHelper extends AppHelper {
|
|
|
$separator = $attributes['separator'];
|
|
|
$interval = $attributes['interval'];
|
|
|
$monthNames = $attributes['monthNames'];
|
|
|
+ $round = $attributes['round'];
|
|
|
$attributes = array_diff_key($attributes, $defaults);
|
|
|
|
|
|
if ($timeFormat == 12 && $hour == 12) {
|
|
|
@@ -2403,7 +2405,18 @@ class FormHelper extends AppHelper {
|
|
|
if ($hour !== null) {
|
|
|
$current->setTime($hour, $min);
|
|
|
}
|
|
|
- $change = (round($min * (1 / $interval)) * $interval) - $min;
|
|
|
+ $changeValue = $min * (1 / $interval);
|
|
|
+ switch ($round) {
|
|
|
+ case 'up':
|
|
|
+ $changeValue = ceil($changeValue);
|
|
|
+ break;
|
|
|
+ case 'down':
|
|
|
+ $changeValue = floor($changeValue);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $changeValue = round($changeValue);
|
|
|
+ }
|
|
|
+ $change = ($changeValue * $interval) - $min;
|
|
|
$current->modify($change > 0 ? "+$change minutes" : "$change minutes");
|
|
|
$format = ($timeFormat == 12) ? 'Y m d h i a' : 'Y m d H i a';
|
|
|
$newTime = explode(' ', $current->format($format));
|