diff --git a/lib/form/duration.php b/lib/form/duration.php index 20c0d053dde..58e7c6c303d 100644 --- a/lib/form/duration.php +++ b/lib/form/duration.php @@ -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); } } diff --git a/lib/form/tests/duration_test.php b/lib/form/tests/duration_test.php index 9a5a1a66090..629ac4d8d14 100644 --- a/lib/form/tests/duration_test.php +++ b/lib/form/tests/duration_test.php @@ -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],