Free Support Forum - aspose.com

First occurrence and start date

In the Aspose.iCalendar API Reference the following line can be read for the RecurrencePattern.StartDate Property:

"The start date of the recurrence pattern always counts as the first occurrences, unless it is excluded in ExDates."

This causes some trouble for me, because I would expect the following behavior:

  • If today is Friday and I specify a RecurrencePattern with start date today, to reoccur 3 times every 1 week on Friday, the start date is my first occurrence.
  • If today is Tuesday and I specify a RecurrencePattern with start date today, to reoccur 3 times every 1 week on Friday, next Friday is my first occurrence.

So sometimes the first occurrence should be the start date, but other times the first occurrence should be second occurrence. Besides that, in the latter case 1 occurrence too little is calculated.

Does anyone now a solution to handle this situation with Aspose.iCalendar?

Kind regards,

Onno Kievit




This “feature” of the iCalendar standard also puzzles us at Aspose. So far we have not found an elegant solution for this. I’m too looking forward to hearing suggestions on this issue.

The problem right now is that one doesn’t know if the start date fits in the recurrence pattern.

I could make a wrapper method for the calculate method to work around the issue:

  • Start calculating from StartDate - 1 with EndDate.Count = 2
  • If the second occurrence is my StartDate, then StartDate fits in the recurrence pattern, otherwise it is not.
  • If the start date fits in the recurrence pattern, just calculate the occurrences.
  • If the start date does not fit in the recurrence pattern, specify ExDates = StartDate and calculate the occurences.

If the iCalendar standard isn’t clear about this issue, Aspose could support both options in the iCalendar component. For example, a boolean parameter could be added to the calculate method indicating wheter the start date should be the first occurrence in the calculated series or not in case the start date does not fit in the recurrence pattern. Internally the iCalendar could follow the same approach as my wrapper method.

My wrapper method is still not working as I would expect. In case the start date does not fit in the recurrence pattern and the option EndDate.Count is used for the end date, EndDate.Count - 1 occurences are calculated.

This would mean ExDates are counted as ocurrences. Is this by design?

For now I can work around the second issue by increasing the count by 1 before starting the calculation.

Kind regards,

Onno Kievit


Is it possible for you guys to write a ReverseRule method?

The way this would work would be for instance, suppose I want the occurence for every friday I would have :-

DTSTART:19960101T000000
RRULE:FREQ=WEEKLY;UNTIL=19961201T000000Z;BYDAY=FR
EXRULE:FREQ=WEEKLY;UNTIL=19961201T000000Z;BYDAY=MO,TU,WE,TH,SA,SU

The EXRULE is needed to ensure the start date is a friday but surely the EXRULE can be computed by you from the RRULE?

The ReverseRule method will simply take the rule and just generate the negative of the rule. so I can do something like :-

RecurrencePattern pattern = new RecurrencePattern();
pattern.StartDate = new DateTime(1996, 1, 1);
RecurrenceRule rule = pattern.RRules.Add();
rule.Frequency = Frequency.Weekly;
rule.Until = new DateTime(1996, 12, 1);
rule.ByDay.Add(new ByDay(DayOfWeek.Friday));

RecurrenceRule exRule = pattern.ExRules.Add(rule.ReverseRule());

As far as I understand you want to solve the same problem with the start date being included into the result set of occurrence dates.

Thanks for the idea. We will eventually come up with a solution and implement it. I'm not sure it will be by reversing the rule, but thanks anyway.

Just wanted to follow up on this thread to see if there was any progress on this issue. Looks like it has been a year since it has been addressed. I have the same requirement that the start date must only be included in the occurence dates if it falls within the pattern.

For example

1. If you wanted every friday of the year, and your start date was 1/5/2007 (a friday), it would be included

2. If you wanted every friday of the year, and your start date was 1/1/2007 (which is a monday), it should not include 1/1/2007 in the occurences.

If you play with the outlook recurrence module it seems to handle these situations correctly. I would expect similiar functionality.

Just wondering if there where any updates to this issue in the module itself, or if anyone has any other workarounds... other than including start date in the exculsion list because it may fall under the pattern.

Hi,

Currently we do not have any immediate plans to implement it in the near future.
Sorry for the inconvenience.

I’d like to add my name to the unofficial “I’d like to see this implemented” list. While I understand that there are two sides to this issue, I’m of the opinion that the calling application shouldn’t have to write logic to figure out when the first occurrence should be, no matter how easy it may be to do so.