From: <dw...@us...> - 2010-12-26 16:50:28
|
Revision: 71 http://nagios.svn.sourceforge.net/nagios/?rev=71&view=rev Author: dworth Date: 2010-12-26 16:50:22 +0000 (Sun, 26 Dec 2010) Log Message: ----------- removed call to date for accurate durations It turns out that for small durations a manual calculation does the job correctly (and in a really ugly way) whereas that is not the case for date(...) Modified Paths: -------------- nagiosvshell/branches/devel/data/read_status.php Modified: nagiosvshell/branches/devel/data/read_status.php =================================================================== --- nagiosvshell/branches/devel/data/read_status.php 2010-12-26 16:50:16 UTC (rev 70) +++ nagiosvshell/branches/devel/data/read_status.php 2010-12-26 16:50:22 UTC (rev 71) @@ -205,8 +205,31 @@ function calculate_duration($beginning) { $now = time(); $duration = ($now - $beginning); - $retval = date('d\d-H\h-i\m-s\s', $duration); + //$retval = date('d\d-H\h-i\m-s\s', $duration); + $retval = coarse_time_calculation($duration); return $retval; } +function coarse_time_calculation($duration) { + $seconds_per_minute = 60; + $seconds_per_hour = $seconds_per_minute * $seconds_per_minute; + $seconds_per_day = 24*$seconds_per_hour; + + $remaining_duration = $duration; + $days = (int)($remaining_duration/$seconds_per_day); + $remaining_duration -= $days*$seconds_per_day; + $hours = (int)($remaining_duration/$seconds_per_hour); + $remaining_duration -= $hours*$seconds_per_hour; + $minutes = (int)($remaining_duration/$seconds_per_minute); + $remaining_duration -= $minutes*$seconds_per_minute; + $seconds = (int)$remaining_duration; + + $retval = ''; + if ($days > 0) { $retval .= sprintf('%d%s', $days,'d-'); } + if ($hours > 0 || $days > 0) { $retval .= sprintf('%d%s', $hours, 'h-'); } + if ($minutes > 0 || $days > 0 || $hours > 0) { $retval .= sprintf('%d%s', $minutes, 'm-'); } + if ($seconds > 0 || $minutes > 0 || $days > 0 || $hours > 0) { $retval .= sprintf('%d%s', $seconds,'s'); } + return $retval; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |