You need to be logged in to view a user's profile.
  1. kirk837
  2. Bugs (Jevents 1.4 for 1.0.x)
  3. Friday, 06 February 2009
Consider a weekly recurrent event on M in weeks 1 and 3. In a month starting on W (eg, July 2009), JEvents places the event on M of weeks 2 and 4. (This is a bug, not a feature.)

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


There are no replies made for this post yet.
Be one of the first to reply to this post!

Members Area

Show your support

Unlike many Joomla calendars we do not charge to download JEvents - please show your support for this project by becoming a member of the JEvents Club Club members get access to early releases, exclusive member support forums, and Silver and Gold members can use many exciting JEvents addons

Your membership will ensure that JEvents continues to be the best events calendar for Joomla.