Skip to content

Commit

Permalink
Update duration display
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed May 16, 2024
1 parent 32d6e25 commit bdbe4e9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions classes/grouped_profile_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand Down
25 changes: 24 additions & 1 deletion classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,37 @@ 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.
* @return 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) {
Expand Down
6 changes: 3 additions & 3 deletions profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand Down

0 comments on commit bdbe4e9

Please sign in to comment.