index : archweb32 | |
Archlinux32 website | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2018-07-26 10:17:46 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-07-26 10:17:46 +0200 |
commit | b5fce4e414842b47d8729af206d5e020dcf6479a (patch) | |
tree | 1231c14c337d0982a93cca1475fc4df858147e3c /lib | |
parent | 3065b6604af855297f26f08a3aae0b5e0b59cc30 (diff) |
-rw-r--r-- | lib/converter.php | 86 |
diff --git a/lib/converter.php b/lib/converter.php new file mode 100644 index 0000000..41951c7 --- /dev/null +++ b/lib/converter.php @@ -0,0 +1,86 @@ +<?php + +# do not include twice +if (function_exists("format_time_duration")) + return; + +require_once "../init.php"; + +function format_time_duration($val) { + $val = floor($val); + $result = ""; + $result = + sprintf( + "%02d", + $val % 60 + ); + $val = floor($val / 60); + if ($val == 0) + return $result; + $result = + sprintf( + "%02d:%s", + $val % 60, + $result + ); + $val = floor($val / 60); + if ($val == 0) + return $result; + $result = + sprintf( + "%d:%s", + $val % 24, + $result + ); + $val = floor($val / 24); + if ($val == 0) + return $result; + $tmp = $val % 7; + $printed_conjunction = true; + if ($tmp > 1) + $result = + sprintf( + "%d days and %s", + $tmp, + $result + ); + elseif ($tmp == 1) + $result = + sprintf( + "%d day and %s", + $tmp, + $result + ); + else + $printed_conjunction = false; + $val = floor($val / 7); + if ($val == 0) + return $result; + if ($printed_conjunction) + $result = + sprintf( + ", %s", + $result + ); + else + $result = + sprintf( + " and %s", + $result + ); + if ($val>1) + $result = + sprintf( + "%d weeks%s", + $val, + $result + ); + else + $result = + sprintf( + "%d week%s", + $val, + $result + ); + return $result; +} |