2009-06-06, 10:59 AM
Of course I could not try all the possible combinations of variables. I have tested out only those involved in the changes I made. However I feel so sure now because the code is simpler than before. For example take a look at this snippet of code:
Old code:
My code:
In the old code, under certain circumstances, the variable $day reached 32 or 33 causing unpredictable behaviors. This is the main cause of the bug reported in the first post.
Old code:
// Start constructing the calendar
$weekdays = fetch_weekday_structure($calendar['startofweek']);
$month_start_weekday = gmdate("w", gmmktime(0, 0, 0, $month, $calendar['startofweek']+1, $year));
// This is if we have days in the previous month to show
if($month_start_weekday != $weekdays[0] || $calendar['startofweek'] != 0)
{
$day = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
$day -= array_search(($month_start_weekday), $weekdays);
$day += $calendar['startofweek']+1;
$calendar_month = $prev_month['month'];
$calendar_year = $prev_month['year'];
}
else
{
$day = $calendar['startofweek']+1;
$calendar_month = $month;
$calendar_year = $year;
}
My code:
// Start constructing the calendar
$weekdays = fetch_weekday_structure($calendar['startofweek']);
$month_start_weekday = gmdate("w", gmmktime(0, 0, 0, $month, 1, $year));
// This is if we have days in the previous month to show
if($month_start_weekday != $weekdays[0])
{
$day = gmdate("t", gmmktime(0, 0, 0, $prev_month['month'], 1, $prev_month['year']));
$day -= array_search($month_start_weekday, $weekdays) - 1;
$calendar_month = $prev_month['month'];
$calendar_year = $prev_month['year'];
}
else
{
$day = 1;
$calendar_month = $month;
$calendar_year = $year;
}
In the old code, under certain circumstances, the variable $day reached 32 or 33 causing unpredictable behaviors. This is the main cause of the bug reported in the first post.