getRecDates bug?

Hi there,

    I'm using the getRecDates function to calculate the recurring dates of an event and an odd bug shows up when I do the following:
  1. I set the recurring type to “day”
  2. I set the option to “week days” (monday through friday)
  3. I start the event on thursday (let’s say today, thursday february 24th 2011)
  4. I set the number of occurrences to 3

This creates the following recurrence pattern (unless I’m mistaken): day_1___1,2,3,4,5

Now, what I would expect getRecDates to give me are three sets of results, one for the 24th, one for the 25th and one for monday the 28th. However, when I set up these parameters, everything freezes up. I went in firebug and traced the code and found the following problem:

The getRecDates function indeed starts and correctly sets the dates for thursday and friday… however the next result to be pushed in the return object is actually Saturday (which shouldn’t even be there). Next it tries to go for Sunday and it consequently gets stuck in a recursive loop in the scheduler.transpose_day_week function. Here is the code for the getRecDates and transpose_day_week functions, in hope it might help you diagnose the problem.

scheduler.getRecDates = function(id, max){
	var ev = typeof id == "object" ? id : scheduler.getEvent(id);
	var count = 0;
	var result = [];
	max = max || 1000;
	
	
	var td = new Date(ev.start_date.valueOf());
	var from = new Date(td.valueOf());
	
	if(!ev.rec_type) {
		return [ { start_date: ev.start_date, end_date: ev.end_date } ];
	}
	this.transpose_type(ev.rec_pattern);
	scheduler.date["transpose_"+ev.rec_pattern](td, from); //td becomes invalid date if [count] is not defined
	
	while (td<ev.start_date || (td.valueOf()+ev.event_length*1000)<=from.valueOf())
		td = this.date.add(td,1,ev.rec_pattern);
	while (td < ev.end_date){
		var ch = this._get_rec_marker(td.valueOf(),ev.id);
		if (!ch){ //not changed element of serie
			var ted = new Date(td.valueOf()+ev.event_length*1000);
			var sed = new Date(td);
			result.push({start_date:sed, end_date:ted});
			td = this.date.add(td,1,ev.rec_pattern);
			count++;
		}
		if (count == max) break;
	}
	return result;
};

scheduler.transpose_day_week=function(sd,list,cor,size,cor2){
	var cday = (sd.getDay()||(scheduler.config.start_on_monday?7:0))-cor;
	for (var i=0; i < list.length; i++) {
		if (list[i]>cday)
			return sd.setDate(sd.getDate()+list[i]*1-cday-(size?cor:cor2));
	}
	this.transpose_day_week(sd,list,cor+size,null,cor);
};

On a side note, I’m aware I may not be using the latest version of these functions so this bug might have been already solved. Regardless, if you could tell me how to fix this issue, I’d be most grateful.

Thanks in advance,

Osu

P.S. I tried with the recurrence pattern day____1,2,3,4,5 thinking the [count] parameter could somehow interfere with the [days] parameter, but when I do that, the td variable becomes an invalid date in the getRecDates function (look for my comment above) and no values are returned.

Hello,

Event created with specified parameters has rec_type “week_1___1,2,3,4,5”.
Does this fact resolve your issue? :slight_smile:

Best regards,
Ilya

Well, I must admit feeling a bit foolish here. It never occurred to me to use “week” as a value when creating a “day” recurrence, but what do you know… it works :slight_smile:.

Thanks for the quick answer… and sorry for the false alarm :slight_smile:.

Osu