
Victor Hugo Cardenas Varon - 2005-03-25 00:07:53 -
In reply to message 1 from Greg Sloman
Hi
You are right, this is a bug.
however, with the dates:
$date = "2005-03-23";
$date2 = "2006-01-22";
echo "$date - $date2: ".$ds->calculate_span($date, $date2);
the result expected is 9 months and 30 days an not
8 months and n (30) days.
I search the cause in the code, and i found
that the problem was in the function days_in_month($month,$year)
returning 0 days in month when the number of the month was zero (0),
because it was returning the element with index -1 in array $ndays
i have fixed the bug including
if($month==0) {
$month=12;
}
in the begining of the function days_in_month($month,$year).
The final code of the days_in_month($month,$year) function is:
function days_in_month($month,$year) {
/* March 24, 2005
Addedd to fix Negative days displayed bug
Bug found by Greg Sloman
The bug was in function days_in_month($month,$year)
returning 0 days in month when the number of the month was zero (0),
because it was returning the element with index -1 in array $ndays
*/
if($month==0) {
$month=12;
}
/****** End of Addedd to fix Negative days displayed bug **********/
$ndays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if ($month==2 && $this->is_leapyear($year)) {
return 29;
}
else return $ndays[$month-1];
}//end function days_in_month
i'll wait some days before i update the package to see
if the fix is not causing some problem in another situation.
Thanks Greg