lib: Add DateFormatter::formatDuration()

refs #6778
This commit is contained in:
Eric Lippmann 2015-05-22 09:49:06 +02:00
parent dd298edb81
commit edd386e14b
1 changed files with 23 additions and 0 deletions

View File

@ -108,6 +108,29 @@ class DateFormatter
return date('Y-m-d H:i:s', (float) $dateTime);
}
/**
* Format a duration
*
* @param int|float $seconds Duration in seconds
*
* @return string
*/
public static function formatDuration($seconds)
{
$minutes = floor((float) $seconds / 60);
if ($minutes < 60) {
$formatted = sprintf('%dm %ds', $minutes, $seconds % 60);
} else {
$hours = floor($minutes / 60);
if ($hours < 24) {
$formatted = sprintf('%dh %dm', $hours, $minutes % 60);
} else {
$formatted = sprintf('%dd %dh', floor($hours / 24), $hours % 24);
}
}
return $formatted;
}
/**
* Format time
*