diff options
author | INOPIAE <inopiae@cacert.org> | 2015-08-09 19:12:51 +0200 |
---|---|---|
committer | Benny Baumann <BenBE@geshi.org> | 2015-08-09 22:23:21 +0200 |
commit | 4edd7b57c0057f9cfab0874a198256b87bd018b7 (patch) | |
tree | 2a623eade7fea29bda28e15692991821448c8fe1 /manager/library/date/HumanReadableTime.php | |
parent | ce38587c8459587d7a03002ebcb4427ed95fb85c (diff) | |
download | cacert-mgr-4edd7b57c0057f9cfab0874a198256b87bd018b7.tar.gz cacert-mgr-4edd7b57c0057f9cfab0874a198256b87bd018b7.tar.xz cacert-mgr-4edd7b57c0057f9cfab0874a198256b87bd018b7.zip |
bug 1396: Codestyle cleanup
Diffstat (limited to 'manager/library/date/HumanReadableTime.php')
-rw-r--r-- | manager/library/date/HumanReadableTime.php | 238 |
1 files changed, 119 insertions, 119 deletions
diff --git a/manager/library/date/HumanReadableTime.php b/manager/library/date/HumanReadableTime.php index 3d33f9a..7c2a7c8 100644 --- a/manager/library/date/HumanReadableTime.php +++ b/manager/library/date/HumanReadableTime.php @@ -11,130 +11,130 @@ require_once(LIBRARY_PATH . '/date/exception.HumanReadableTimeException.php'); class HumanReadableTime { - /** - * normalize an HRT string, convert from HRT to seconds and then convert back to - * HRT - * @param string $hrt - * @param string $maxunit - * @return string - */ - public static function NormalizeHRT($hrt, $maxunit = 'w') { - return self::Seconds2HR(self::HR2Seconds($hrt), $maxunit); - } + /** + * normalize an HRT string, convert from HRT to seconds and then convert back to + * HRT + * @param string $hrt + * @param string $maxunit + * @return string + */ + public static function NormalizeHRT($hrt, $maxunit = 'w') { + return self::Seconds2HR(self::HR2Seconds($hrt), $maxunit); + } - /** - * convert string / interger which contains an interval length to - * human readable format (1w2d7h) - * - * if $maxunit is set, it defines the biggest unit in output (i.e. $maxunit = 'h' will - * allow only hms) - * - * @param string|integer $seconds - * @param string $maxunit - * @return string - */ - public static function Seconds2HR($seconds, $maxunit = 'w') { - $maxunit = trim(strtolower($maxunit)); - $allowed = array('w' => 0, 'd' => 0, 'h' => 0, 'm' => 0, 's' => 0); - if (!in_array($maxunit, array_keys($allowed), true)) - throw new HumanReadableTimeException('illegal value for maxunit: "' . $maxunit . '"'); - foreach ($allowed as $key => $value) { - if ($maxunit == $key) - break; - unset($allowed[$key]); - } + /** + * convert string / interger which contains an interval length to + * human readable format (1w2d7h) + * + * if $maxunit is set, it defines the biggest unit in output (i.e. $maxunit = 'h' will + * allow only hms) + * + * @param string|integer $seconds + * @param string $maxunit + * @return string + */ + public static function Seconds2HR($seconds, $maxunit = 'w') { + $maxunit = trim(strtolower($maxunit)); + $allowed = array('w' => 0, 'd' => 0, 'h' => 0, 'm' => 0, 's' => 0); + if (!in_array($maxunit, array_keys($allowed), true)) + throw new HumanReadableTimeException('illegal value for maxunit: "' . $maxunit . '"'); + foreach ($allowed as $key => $value) { + if ($maxunit == $key) + break; + unset($allowed[$key]); + } - $seconds = intval($seconds); - $hrt = ''; - foreach ($allowed as $key => $value) { - switch ($key) { - case 'w': - $tmp = intval($seconds / (7*86400)); - if ($tmp > 0) - $seconds %= (7*86400); - $allowed[$key] += $tmp; - break; - case 'd': - $tmp = intval($seconds / (86400)); - if ($tmp > 0) - $seconds %= (86400); - $allowed[$key] += $tmp; - break; - case 'h': - $tmp = intval($seconds / (3600)); - if ($tmp > 0) - $seconds %= (3600); - $allowed[$key] += $tmp; - break; - case 'm': - $tmp = intval($seconds / (60)); - if ($tmp > 0) - $seconds %= (60); - $allowed[$key] += $tmp; - break; - case 's': - $allowed[$key] += $seconds; - break; - } - } + $seconds = intval($seconds); + $hrt = ''; + foreach ($allowed as $key => $value) { + switch ($key) { + case 'w': + $tmp = intval($seconds / (7*86400)); + if ($tmp > 0) + $seconds %= (7*86400); + $allowed[$key] += $tmp; + break; + case 'd': + $tmp = intval($seconds / (86400)); + if ($tmp > 0) + $seconds %= (86400); + $allowed[$key] += $tmp; + break; + case 'h': + $tmp = intval($seconds / (3600)); + if ($tmp > 0) + $seconds %= (3600); + $allowed[$key] += $tmp; + break; + case 'm': + $tmp = intval($seconds / (60)); + if ($tmp > 0) + $seconds %= (60); + $allowed[$key] += $tmp; + break; + case 's': + $allowed[$key] += $seconds; + break; + } + } - $hrt = ''; - foreach ($allowed as $key => $value) { - if ($value > 0) - $hrt .= sprintf('%d%s', $value, $key); - } - return $hrt; - } + $hrt = ''; + foreach ($allowed as $key => $value) { + if ($value > 0) + $hrt .= sprintf('%d%s', $value, $key); + } + return $hrt; + } - /** - * parse a string of 3h2m7s and return the number of seconds as integer - * add "s" to the end of the number if $addsecond is set to true - * @param string $hr - * @param boolean $addsecond - * @return integer|string - */ - public static function HR2Seconds($hr, $addsecond = false) { - $hr = trim($hr); - if ($hr == '') { - if ($addsecond === true) - return '0s'; - else - return 0; - } + /** + * parse a string of 3h2m7s and return the number of seconds as integer + * add "s" to the end of the number if $addsecond is set to true + * @param string $hr + * @param boolean $addsecond + * @return integer|string + */ + public static function HR2Seconds($hr, $addsecond = false) { + $hr = trim($hr); + if ($hr == '') { + if ($addsecond === true) + return '0s'; + else + return 0; + } - $hr = strtolower($hr); + $hr = strtolower($hr); - $matches = array(); - if (preg_match_all('/([0-9]*)([wdhms])/', $hr, $matches, PREG_SET_ORDER) > 0) { - $interval = 0; - for ($i = 0; $i < count($matches); $i++) { - switch ($matches[$i][2]) { - case 'w': - $interval += $matches[$i][1] * 7 * 86400; - break; - case 'd': - $interval += $matches[$i][1] * 86400; - break; - case 'h': - $interval += $matches[$i][1] * 3600; - break; - case 'm': - $interval += $matches[$i][1] * 60; - break; - case 's': - $interval += $matches[$i][1]; - break; - } - } - if ($addsecond === true) - return sprintf('%ds', $interval); - else - return $interval; - } + $matches = array(); + if (preg_match_all('/([0-9]*)([wdhms])/', $hr, $matches, PREG_SET_ORDER) > 0) { + $interval = 0; + for ($i = 0; $i < count($matches); $i++) { + switch ($matches[$i][2]) { + case 'w': + $interval += $matches[$i][1] * 7 * 86400; + break; + case 'd': + $interval += $matches[$i][1] * 86400; + break; + case 'h': + $interval += $matches[$i][1] * 3600; + break; + case 'm': + $interval += $matches[$i][1] * 60; + break; + case 's': + $interval += $matches[$i][1]; + break; + } + } + if ($addsecond === true) + return sprintf('%ds', $interval); + else + return $interval; + } - if ($addsecond === true) - return '0s'; - else - return 0; - } + if ($addsecond === true) + return '0s'; + else + return 0; + } } |