mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-69507 duration form field: should return an int number of seconds
This commit is contained in:
parent
e5a0f11b5e
commit
58b7986776
2 changed files with 5 additions and 2 deletions
|
@ -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
|
||||
|
@ -300,6 +300,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],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue