Determine whether or not a date is covered by a recurring ev

Is there a standard piece of code that I can send in a date to that will tell me whether or not that date is affected by a recurring event?

pseudo code would be something like this…

function dateCovered(dateTested, event)
{
type = event.type;
countInterval = event.countInterval;
if (type == day)
if(countInterval == 1)
return true;
else
{
dateDiff = dateTested - event.start_date.totalDays;

if (dateDiff/countInterval == 0)
return true;
}
elseif (type == month)
{
… work out here whether or not the month based event covers the date
}

Hi,
you can pick all events that happens at the time you want to check, and see if the event you are checking is one of these events:

[code]function dateCovered(dateTested, event){
var events = scheduler.getEvents(dateTested, scheduler.date.add(dateTested, scheduler.config.time_step, “minute”));
// or
//var events = scheduler.getEvents(dateTested, dateTested);

for(var i = 0; i < events.length; i++){
	if(events[i].id == event.id || events[i].event_pid == event.id){
		return true;
	}
}

return false;

}[/code]

docs.dhtmlx.com/scheduler/api__s … vents.html

Problem is, when I want to check for coverage, I do not have the scheduler on the screen, I have to do it from the database, but I cannot work out the algorithm to work out from the database whether or not the time frame is covered by an event…

Can you send me the algorithm that the scheduler uses to work this out?

Hello,
receiving dates of recurring events may be not trivial, we do not have a documented algorithm although it is implemented in some helpers.

If you have a .NET library of a scheduler you can use this
scheduler-net.com/docs/recurring … ing_events

var helper = new DHXEventsHelper(); var items = helper.GetOccurrences(events, dateTimeFrom, dateTimeTo);
events - IEnumerable collection of event records - the helper expects them to have properties named as required by scheduler model - ie.

public int id {get;set;} public string text {get;set;} public DateTime start_date {get;set;} public DateTime end_date {get;set;} public string rec_type {get;set;} public long event_length {get;set;} public int event_pid {get;set;}

dateTimeFrom, dateTimeTo - date range you need to check.

So basically what you do

[code]var from = someDate;
var to = someOtherDate;

var events = datasource.Where(e => e.StartDate < to && e.EndDate > from);// select all series and events that overlaps given date from the database

var instances = helper.GetOccurrences(events, from, to);// parse recurring records into individual instances that happens in a given timeframe[/code]

But this does not seem to take into account the fact that some events have dates within the timeframe that are actually deletions of recurring event (which is really the problem I am trying to resolve). I can quite easily find all the events with startdate and enddates within my timeframe - the problem is working out which ones are either deletions rather than events per se… and which ones only operate once per month or once per week or whatever and therefore do not apply to the time period I am looking at (e.g. if I am looking at the period Mon Sept 21 - Wed Sept 23rd, there are many events that cover that time period but some only occur on Fridays each week or on weekends each week and so are not covering the time period

Hello,
DHXEventsHelper.GetOccurrences parses the recurring records and return array of individual occurences that happens inside a given timespan.

If you have monthly event that happens 21th day each month, and you use .getOccurrences(events, new Date(2015, 9, 21), new Date(2015, 9, 23)) - it should return object with the date/time of that particular occurrence, and return nothing if there is no occurrences on that date (if it has been deleted or moved from that particular date).

I.e. helper was implemented for exactly for such use-cases. If it returns not expected values in some cases - please provide some test data so we could reproduce the issue locally