diff --git a/classes/grouped_profile_table.php b/classes/grouped_profile_table.php index 02c4582..b94b09b 100644 --- a/classes/grouped_profile_table.php +++ b/classes/grouped_profile_table.php @@ -126,7 +126,7 @@ public function col_mincreated(\stdClass $record): string { * @return string */ public function col_maxduration(\stdClass $record): string { - return helper::duration_display($record->maxduration, !$this->is_downloading()); + return helper::duration_display_text($record->maxduration, !$this->is_downloading()); } /** @@ -136,7 +136,7 @@ public function col_maxduration(\stdClass $record): string { * @return string */ public function col_minduration(\stdClass $record): string { - return helper::duration_display($record->minduration, !$this->is_downloading()); + return helper::duration_display_text($record->minduration, !$this->is_downloading()); } /** diff --git a/classes/helper.php b/classes/helper.php index c93c434..1da07ef 100644 --- a/classes/helper.php +++ b/classes/helper.php @@ -88,7 +88,7 @@ public static function reason_display(int $reason): string { } /** - * Returns a formatted time duration in a human readable format. + * Returns a formatted time duration in h:m:s format. * * @param float $duration * @param bool $markup If true, then use markup on the result. @@ -96,6 +96,29 @@ public static function reason_display(int $reason): string { * @throws \Exception */ public static function duration_display(float $duration, bool $markup = true): string { + if (!$markup) { + return $duration; + } + + $s = (int) $duration; + $h = $s / 3600; + $m = ($s % 3600) / 60; + $s = $s % 60; + if ($h >= 1) { + return sprintf('%d:%02d:%02d', $h, $m, $s); + } + return sprintf('%d:%02d', $m, $s); + } + + /** + * Returns a formatted time duration in a human readable format. + * + * @param float $duration + * @param bool $markup If true, then use markup on the result. + * @return string + * @throws \Exception + */ + public static function duration_display_text(float $duration, bool $markup = true): string { // Variable $markup allows a different format when viewed (true) vs downloaded (false). if ($markup) { if (intval($duration) > 10) { diff --git a/profile.php b/profile.php index 54032a3..8f1105b 100644 --- a/profile.php +++ b/profile.php @@ -122,11 +122,11 @@ $data['finished'] = userdate($data['finished']); $duration = $data['duration']; -$data['duration'] = helper::duration_display($duration, true); +$data['duration'] = helper::duration_display_text($duration, true); if (isset($data['lockwait'])) { $lockwait = $data['lockwait']; - $data['lockwait'] = helper::duration_display($lockwait, true); - $data['lockheld'] = helper::duration_display($data['lockheld'], true); + $data['lockwait'] = helper::duration_display_text($lockwait, true); + $data['lockheld'] = helper::duration_display_text($data['lockheld'], true); $data['lockwaiturl'] = helper::lockwait_display_link($data['lockwaiturl'], $lockwait); $data['lockwaiturlhelp'] = helper::lockwait_display_help($OUTPUT, $data['lockwaiturl']);