How can I exclude DTSTART from generated events if its day not among days specified by BYDAY?

吃可爱长大的小学妹 提交于 2020-01-07 03:00:31

问题


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:


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.



来源:https://stackoverflow.com/questions/35197441/how-can-i-exclude-dtstart-from-generated-events-if-its-day-not-among-days-specif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!