mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
parent
dd298edb81
commit
edd386e14b
@ -108,6 +108,29 @@ class DateFormatter
|
|||||||
return date('Y-m-d H:i:s', (float) $dateTime);
|
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
|
* Format time
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user