mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 15:32:13 +00:00
added functions getReadableDuration() and getReadableDurationArray()
This commit is contained in:
parent
6c01bb7aff
commit
65c5f4ad33
|
@ -33,6 +33,33 @@ function getLongReadableDate($timestamp) {
|
|||
return date("d/m/Y H:i", $timestamp);
|
||||
}
|
||||
|
||||
function getReadableDuration($secs) {
|
||||
$s = "";
|
||||
foreach ( getReadableDurationArray($secs) as $k => $v ) {
|
||||
if ( $v ) $s .= $v." ".($v==1? substr($k,0,-1) : $k).", ";
|
||||
}
|
||||
|
||||
return substr($s, 0, -2);
|
||||
}
|
||||
|
||||
function getReadableDurationArray($secs) {
|
||||
$units = array(
|
||||
getMLText("weeks") => 7*24*3600,
|
||||
getMLText("days") => 24*3600,
|
||||
getMLText("hours") => 3600,
|
||||
getMLText("minutes") => 60,
|
||||
getMLText("seconds") => 1,
|
||||
);
|
||||
|
||||
foreach ( $units as &$unit ) {
|
||||
$quot = intval($secs / $unit);
|
||||
$secs -= $quot * $unit;
|
||||
$unit = $quot;
|
||||
}
|
||||
|
||||
return $units;
|
||||
}
|
||||
|
||||
//
|
||||
// The original string sanitizer, kept for reference.
|
||||
//function sanitizeString($string) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user