MDL-69507 duration form field: should return an int number of seconds
This commit is contained in:
@@ -34,7 +34,7 @@ require_once($CFG->libdir . '/form/text.php');
|
||||
* Duration element
|
||||
*
|
||||
* HTML class for a length of time. For example, 30 minutes of 4 days. The
|
||||
* values returned to PHP is the duration in seconds.
|
||||
* values returned to PHP is the duration in seconds (an int rounded to the nearest second).
|
||||
*
|
||||
* @package core_form
|
||||
* @category form
|
||||
@@ -301,6 +301,7 @@ class MoodleQuickForm_duration extends MoodleQuickForm_group {
|
||||
if ($this->_options['optional'] && empty($valuearray['enabled'])) {
|
||||
return $this->_prepareValue(0, $assoc);
|
||||
}
|
||||
return $this->_prepareValue($valuearray['number'] * $valuearray['timeunit'], $assoc);
|
||||
return $this->_prepareValue(
|
||||
(int) round($valuearray['number'] * $valuearray['timeunit']), $assoc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,8 @@ class core_form_duration_testcase extends basic_testcase {
|
||||
public function export_value_cases(): array {
|
||||
return [
|
||||
[10, '10', 1],
|
||||
[9, '9.3', 1],
|
||||
[10, '9.5', 1],
|
||||
[180, '3', MINSECS],
|
||||
[90, '1.5', MINSECS],
|
||||
[7200, '2', HOURSECS],
|
||||
|
||||
Reference in New Issue
Block a user