The error arises in line 290 of commonfunctions.php,
$adjustment = 1 + (7+$reccurweekdays[$i]-$daynum_of_first_in_month)%7;
The correct code is the simpler and obvious
$adjustment = $reccurweekdays[$i]-$daynum_of_first_in_month + 1;
This displays weekly events correctly.
However, this corrected code creates invisible incorrect event days. In the example, it makes $adjustment=-1, so, in week 1, $next_recurweekday would also be -1. mktime() will convert this to the next-to-the-last day of the previous month. This is _not_ a legitimate event day, because the event does not occur in weeks 4 or 5. This error does not create a problem in the calendar because of the way the event days returned by mosEventRepeatArrayPeriod() are used in later code. However, it would be better not to return this erroneous result at all. So a guard against non-positive $next_recurweekday should be introduced.
The corrected expression, replacing the code between lines 288-298, is then
if (count($repeatweeks)>0){
$daynum_of_first_in_month = intval(date( 'w', mktime( 0, 0, 0, $month, 1, $year )));
$adjustment = $reccurweekdays[$i]-$daynum_of_first_in_month + 1; /*corrected line*/
// Now find repeat weeks for the month
foreach ($repeatweeks as $weeknum) {
$next_recurweekday = ($adjustment + ($weeknum-1)*7);
if ($next_recurweekday > 0){ // guard against erroneous events in previous month
$nextDate = mktime( 0, 0, 0, $month, $next_recurweekday, $year );
if ($nextDate>=$event_start_date && $nextDate<=$event_end_date) $eventDays[$nextDate]=true;
}
}
}
=============
Is this a bug or a feature?
For the every-two and every-three cases, there is a similar behavior: If the start date is between two days of an every two week event, then the later-in-the-week day will repeat as expected, but the earlier-in-the-week day will repeat in the alternate weeks -- the events won't occur together in the same week. I find this surprising, but neither right nor wrong. This behavior arises from the same kind of computation, involving (7+...)%7.
If JEvents had the very important "cancel this day's occurrence only" feature, then both patterns (in the same week / in alternate weeks) would be possible.
Kim Kirkpatrick