Edward Kay wrote:
maybe someone can figure why sometimes i get negative values for seconds..

$job['finished'] and $job['finished'] are both unix timestamp.
i subtract both to get how many seconds some thing took.. well you
should be able to read the rest. sometimes it works fine but other times
i get negative seconds.


$job['run_time']  = ($job['finished'] - $job['started']);

$minutes = number_format($job['run_time'] / 60, 0, '', '');

// seconds left after calculating minutes
$seconds = (($job['run_time']- 60) * $minutes);

$job['runtime'] = $minutes . ' mins ' . $seconds . ' secs';


If $job['run_time'] < 60 then clearly $seconds will be negative.

Why don't you use:

$minutes = floor($job['run_time'] / 60);
$seconds = $job['run_time'] % 60;

Edward

yeah that seems more simple, but i do check if it's less than 60 seconds.

   $job['run_time'] = ($job['finished'] - $job['started']);

   if ($job['run_time'] < 60)
   {
       $job['runtime'] = $rsync['run_time'] . ' secs';
   }
   else
   {
       $minutes = number_format($job['run_time'] / 60, 0, '', '');
       $seconds = (($job['run_time'] - 60) * $minutes);

       $job['runtime'] = $minutes . ' mins ' . $seconds . ' secs';
   }

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to