Skip to content

Commit

Permalink
MDL-69507 duration form field: should return an int number of seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Aug 20, 2020
1 parent e5a0f11 commit 58b7986
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/form/duration.php
Expand Up @@ -34,7 +34,7 @@
* 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
Expand Down Expand Up @@ -300,6 +300,7 @@ function exportValue(&$submitValues, $assoc = false) {
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);
}
}
2 changes: 2 additions & 0 deletions lib/form/tests/duration_test.php
Expand Up @@ -145,6 +145,8 @@ public function test_seconds_to_unit_different_default_unit() {
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],
Expand Down

0 comments on commit 58b7986

Please sign in to comment.