date() should not be used to express duration

Bug #707235 reported by Hugo Bernier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Nagios Visual Shell
New
Undecided
Unassigned

Bug Description

the function calculate_duration, in read_status.php uses duration to evaluate the result of one timestamp being subtracted to another.

The result is actually a date early in the unix epoch, which I don't think is the intended effect.

I've adapted the function code below, and the output to exemplify the problem.

<?php
$beginning = '1295908827';
$now = time();
$duration = ($now - $beginning);
$duration_in_minutes = ( $duration / 60 );
print("Duration of outage in minutes: $duration_in_minutes <br/>");
$original_duration = date('d\d-H\h-i\m-s\s', $duration);
$epoch_duration = date('r', $duration);
print("Date in unix epoch format: $epoch_duration <br/>");
print("duration as it shows up in vshell: $original_duration <br/>");
?>

Here is what I get in my browser, after running it on my server:

Duration of outage in minutes: 213.01666666667
Date in unix epoch format: Wed, 31 Dec 1969 22:33:01 -0500
duration as it shows up in vshell: 31d-22h-33m-01s

What you need is something like the code here, but I'm not sure what the licensing terms for this site are.

http://snipplr.com/view.php?codeview&id=2711

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.