search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

RecurrenceExpander.Expand Issue

Asked by Stephanie
8 years ago.

How does this work? I have used this in many locations without any issues, but I am having trouble now. I am getting events from a database and trying to 'block; other openings on the calendar. Things are working fine until I edit a single occurrence of an event.

For example I have a recurring event that is scheduled to start on 3/8 @ 9:15am to repeat weekly 3 times. I then edited the occurrence on 3/8 and moved it to 3/1 @ 9:15am. When I select the events from the database I get the following:

dtEvents.Rows[0].ItemArray
{object[7]}
[0]: 671
[1]: {3/1/2016 9:15:00 AM}
[2]: {3/1/2016 10:15:00 AM}
[3]: "01:00:00"
[4]: "Njcw#1#M#2016-03-08T09:15:00"
[5]: 1
[6]: {3/1/2016 10:15:00 AM}

I use the following to get expand the events.

DataTable dtEventsExpanded = RecurrenceExpander.Expand(dtEvents, "Recurrence", "StartDate", "CurrentEndDate", "CalendarEventID", "Master2", e.Start, e.End);

but in the expanded event table there is nothing.

e.Start
{3/1/2016 9:15:00 AM}
Date: {3/1/2016 12:00:00 AM}
Day: 1
DayOfWeek: Tuesday
DayOfYear: 61
Hour: 9
Kind: Unspecified
Millisecond: 0
Minute: 15
Month: 3
Second: 0
Ticks: 635924205000000000
TimeOfDay: {09:15:00}
Year: 2016
e.End
{3/1/2016 10:15:00 AM}
Date: {3/1/2016 12:00:00 AM}
Day: 1
DayOfWeek: Tuesday
DayOfYear: 61
Hour: 10
Kind: Unspecified
Millisecond: 0
Minute: 15
Month: 3
Second: 0
Ticks: 635924241000000000
TimeOfDay: {10:15:00}
Year: 2016

I event tried subtracting a year from the start and adding a year to the end:

e.Start.AddYears(-1)
{3/1/2015 9:15:00 AM}
Date: {3/1/2015 12:00:00 AM}
Day: 1
DayOfWeek: Sunday
DayOfYear: 60
Hour: 9
Kind: Unspecified
Millisecond: 0
Minute: 15
Month: 3
Second: 0
Ticks: 635607981000000000
TimeOfDay: {09:15:00}
Year: 2015
e.End.AddYears(1)
{3/1/2017 10:15:00 AM}
Date: {3/1/2017 12:00:00 AM}
Day: 1
DayOfWeek: Wednesday
DayOfYear: 60
Hour: 10
Kind: Unspecified
Millisecond: 0
Minute: 15
Month: 3
Second: 0
Ticks: 636239601000000000
TimeOfDay: {10:15:00}
Year: 2017

but still get nothing when expanded.

What am I missing?

Comment posted by Stephanie
8 years ago.

Still looking for an answer?....??

Answer posted by Dan Letecky [DayPilot]
8 years ago.

The current implementation doesn't support creating an exception for the first occurrence (the one stored in the master record).

If you create an exception with the start date that corresponds to the master start it will be ignored. Note that the master start doesn't have to meet the recurrence rule (you can have the first event on Wednesday but the rule is to repeat every Monday).

What probably happened in your case is that you have overwritten the rule in the master record with the exception rule. That turned the master into an exception and the rule is no longer defined anywhere.

Comment posted by Stephanie
8 years ago.

Thanks Dan. The master rule is still there as well. It doesn't seem to work for the last occurrence either. So what are we suppossed to do? Our clients will likely need to reschedule the first and/or last occurrences at times and we have to properly show things as 'booked' on the calendar or they will get VERY mad...

Comment posted by Stephanie
8 years ago.

Just to follow up. If I have an appointment that repeats 3 times, for example - Today (3/16), 3/23 and 3/30. If I move the 3/16 occurrence to 3/17 things work fine, but if I move it to 3/15 it is no longer available when expanding the occurrences. That is what is causing the issue.

The same happens for the 3/30 occurrence. If I move it to 3/29 it works fine. If I move it to 3/31 it will not be there to use when expanding the occurrences.

I believe that regardless of if I move the first to before the MASTER start date or the end to after the MASTER end date, those should still be there since they are really occurrences and show on the calendar control just fine. They are just not there when expanding things.

Comment posted by Dan Letecky [DayPilot]
8 years ago.

When using RecurrenceExpander, what maxChange value do you use?

public static DataTable Expand(DataTable source, string recurrenceFieldName, string startFieldName, string endFieldName, string idFieldName, string recurrenceMasterIdFieldName, DateTime rangeStart, DateTime rangeEnd, TimeSpan maxChange);

This determines how far in the future (beyond rangeEnd) the expander should look for regular occurrences that are replaced by exceptions (exceptions that move the event back to the past).

Other things you might want to check:

1. The rangeStart and rangeEnd values.
2. Whether the exceptions from the past are loaded from the database and passed to the expander in source.

Let me know if it didn't help.

Comment posted by Stephanie
8 years ago.

THanks! Here is what I currently have:

DataTable dtEventsExpanded = RecurrenceExpander.Expand(dtEvents, "Recurrence", "StartDate", "CurrentEndDate", "CalendarEventID", "Master2", e.Start, e.End);

I tried using e.Start minus a year and e.End plus a year, but I don't see a MaxChange being passed. I will try that out and see how that works.

Comment posted by Stephanie
8 years ago.

Okay, I changed the expand to this:

DataTable dtEventsExpanded = RecurrenceExpander.Expand(dtEvents, "Recurrence", "StartDate", "CurrentEndDate", "CalendarEventID", "Master2", e.Start.AddYears(-1), e.End.AddYears(1), new TimeSpan(365, 0, 0, 0));

And I still don't get that exception information...

Comment posted by Dan Letecky [DayPilot]
8 years ago.

Could you please list the the input records you send to the RecurrenceExpander?

Is it still the one record from the original question above?

Comment posted by Stephanie
8 years ago.

Here are the master and exception records in the DB:

446, '2016-03-16 12:00:00', '2016-03-30 13:00:00', 'New PT Session', 'NDQ2#2#C#T#2#VyAzICo=', 0, 4, 4, 0, 11, 8, '', '01:00:00', 65.00, b, b, 2, '2016-03-16 11:50:20', '2016-03-16 11:50:20', 'df617157-beab-4382-a469-8f9470b32a93', b, 0, 1, 0, '0', 10, b, b

455, '2016-03-15 12:00:00', '2016-03-15 13:00:00', 'New PT Session', 'NDQ2#1#M#2016-03-16T12:00:00', 446, 4, 4, 0, 11, 8, '', '01:00:00', 65.00, b, b, 2, '2016-03-16 13:12:23', '2016-03-16 13:12:23', 'fc7d7561-5744-4eca-b5cb-67be0d2ec4bb', b, 0, 2, 0, '0', 10, b, b

I now have 38 records that go into the Expand method, but when I move the exception to the day before the start of the event it will not be in the expanded table...

Comment posted by Dan Letecky [DayPilot]
8 years ago.

Thanks - let me check that.

Comment posted by Stephanie
8 years ago.

Great! Thank you. Please let me know what you find.

Comment posted by Stephanie
8 years ago.

Any word on this? We are waiting to release our next update on this item. Thanks!!

Comment posted by Dan Letecky [DayPilot]
8 years ago.

Stephanie,

Sorry for the delay. I'll know more tomorrow.

Comment posted by Dan Letecky [DayPilot]
8 years ago.

Stephanie,

Sorry for the delay. I did a quick test using the following code:

    DataTable table = RecurrenceExpander.Expand(recurring(), "recurrence", "start", "end", "id", "master",
                                                    new DateTime(2016, 1, 1), new DateTime(2017, 1, 1));

    private DataTable recurring()
    {
        DataTable dt;
        dt = new DataTable();
        dt.Columns.Add("start", typeof(DateTime));
        dt.Columns.Add("end", typeof(DateTime));
        dt.Columns.Add("name", typeof(string));
        dt.Columns.Add("id", typeof(string));
        dt.Columns.Add("column", typeof(string));
        dt.Columns.Add("recurrence", typeof(string));
        dt.Columns.Add("resourceid", typeof(int));

        DataRow dr;

        dr = dt.NewRow();
        dr["id"] = 446;
        dr["start"] = Convert.ToDateTime("2016-03-16 12:00:00");
        dr["end"] = Convert.ToDateTime("2016-03-16 12:00:00");
        dr["name"] = "Recurring";
        dr["recurrence"] = "NDQ2#2#C#T#2#VyAzICo=";
        dt.Rows.Add(dr);

        dr = dt.NewRow();
        dr["id"] = 455;
        dr["start"] = Convert.ToDateTime("2016-03-15 12:00:00");
        dr["end"] = Convert.ToDateTime("2016-03-15 13:00:00");
        dr["name"] = "Exception 1";
        dr["recurrence"] = "NDQ2#1#M#2016-03-16T12:00:00";
        dt.Rows.Add(dr);

        return dt;
    }

The output "table" has the following data:

start	end	name	id	column	recurrence	resourceid	master
------------------------------------------------------------------------------
3/15/2016 12:00:00 PM	3/15/2016 1:00:00 PM	Exception 1	455	 	NDQ2#1#M#2016-03-16T12:00:00	 	446
3/23/2016 12:00:00 PM	3/23/2016 12:00:00 PM	Recurring	 	 	NDQ2#2#C#T#2#VyAzICo=	 	446
3/30/2016 12:00:00 PM	3/30/2016 12:00:00 PM	Recurring	 	 	NDQ2#2#C#T#2#VyAzICo=	 	446

That seems to be correct. Are you getting different results?

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.