2
votes

I'm using google-rfc-2445 to generate repeating events according to according to rfc-2445:

The "DTSTART" property for a "VEVENT" specifies the inclusive start of the event. For recurring events, it also specifies the very first instance in the recurrence set.

So, for example RRULE for event which occures every Friday 5 times:

DTSTART;TZID=US-Eastern:20160204T090000
RRULE:FREQ=WEEKLY;COUNT=5;BYDAY=FR;INTERVAL=1;

So according to rfc-2445 it will generate 6 events. First event on Thursday 4 February 2016, second event on Friday 5 February 2016, and so on.

How can I achieve that it will exclude first event if it isn't in a pattern? In the example above it should exclude first occurrence, 4 February 2016. In case of defining DTSTART;TZID=US-Eastern:20160205T090000 which is Friday it should leave first occurrence.

Can it be done by defining such "exclusion rule" in RRULE itself or I need to make a check in a code and if DTSTART isn't the same day as defined in BYDAY I should look for closest date in code (manually) and change DTSTART accordingly?

UPDATE Ok, according to rfc-2445 and this question on google group: https://groups.google.com/forum/#!topic/google-rfc-2445/xqYFe411ysA

The "EXDATE" property can be used to exclude the value specified in
"DTSTART". However, in such cases the original "DTSTART" date MUST
still be maintained by the calendaring and scheduling system because
the original "DTSTART" value has inherent usage dependencies by other properties such as the "RECURRENCE-ID".

it looks that I need to use EXDATE property to achieve what do I need. Trying to achieve this by following RRULE:

EXDATE;TZID=Asia/Jerusalem:20160210T000000 
RRULE:FREQ=WEEKLY;COUNT=5;BYDAY=WE;INTERVAL=1;

And start date is: 2016-02-10T00:00:00.000+02:00 in the following code:

DateTimeIterable dti = DateTimeIteratorFactory.createDateTimeIterable(RRULE, DTSTART, dateTimeZone, true);

But it returns only 4 events, so it always remove first event.

1
This will generate 5 events, due to COUNT=5. DTSTART counts as the first instance, so there will be only 4 Friday events.Marten
No, It returns 6 events, event which specified by DTSTART and 5 events by pattern.Anatoly
That's a bug in the library. RFC 5545 clearly says The COUNT rule part defines the number of occurrences at which to range-bound the recurrence. The "DTSTART" property value always counts as the first occurrence.Marten
FTR, that's also true for RFC 2445Marten
As you noticed EXDATE is not a solution. Unless you have support for that in your recurrence library it's not trivial to determine if DTSTART matches the rule or not. Given that most implementations return DTSTART as the first instance, why do you want to handle it differently?Marten

1 Answers

1
votes

From the description of the problem you give, you will get 6 events when DTSTART is added and you would not want it to be part of the list of instances and 5 events when it is a good date.

So what you want is to only get the last 5 events, which is possible by using the BYSETPOS in your RRULE, the following should do the trick:

BYSETPOS=-5,-4,-3,-2,-1

which will return in all cases the last 5 events that your RRULE gives regardless if the DTSTART is matching the pattern of your RRULE or not.