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

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.

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.

Related

RRULE 20 days after every 15th in a month,in icalendar (RFC 5545)?

I'm searching a way to express a situation like this in icalendar: an event happens every month, x days after a given date.
e.g.: 20 days after 15th day in every month. so, it might be 3rd, 4th, 5th,6th( like February )
if bymonthday can be set to 35, it's ok.
But in outlook this won't work.
How to solve this question?
You could perhaps try adding ";BYSETPOS=20" to the rule. The specification shows an example of BYSETPOS when using it with BYDAY, but it is not clear to me how it is handled when using BYMONTHDAY. I don't see another option looking at the spec.
http://icalendar.org/iCalendar-RFC-5545/3-3-10-recurrence-rule.html
http://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html
Sorry, what you want is not possible with a RRULE.
What you want is RRULE:FREQ=MONTHLY;BYMONTHDAY=35. Unfortunately, it's invalid - BYMONTHDAY can't exceed 31.
BYSETPOS won't work either. In RFC 5545, page 43 under BYSETPOS is the following:
"BYSETPOS operates on a set of recurrence instances in one interval of the recurrence rule."
That means you can't get a value beyond the interval. If you use Monthly you are restricted to the one month.
If you want to experiment with some RRULEs try my recurrence rule (RRULE parser) at
http://balsoftware.net/index.php/open-source/rrule-parser/

iCalendar RRULE/RECUR for Thanksgiving weekend?

Is there an "easy" way to create yearly events for "Thanksgiving weekend", meaning an event starting on the 4th Thursday of November (with Sunday as the first weekday), and ending on the following Sunday?
As nearly as I can tell, things like RRULE and RECUR let you create recurring events with zero duration (ie, points in time), but not recurring events that last over a period of time.
What am I missing?
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY:4TH;WKST=SU
You're definitely not restricted to 0 duration events. You can simply specify a DTSTART and DTEND (or DURATION) to get the full weekend.
To elaborate on Evert's answer, to specify a 4 day long event, you just need to specify the DTSTART and DTEND such as below:
DTSTART;VALUE=DATE:20151126 DTEND;VALUE=DATE:20151130 RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=4TH;WKST=SU
the justification comes from below section of RFC5545:
RFC5545 3.6.1The "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. The "DTEND" property
for a "VEVENT" calendar component specifies the non-inclusive end
of the event.

single icalendar rule for 1st weekday of multiple months every year?

Is it possible to specify an event to occur on the 1st weekday of multiple months every year in a single RRULE? Using January and June as a test case, my initial attempt was:
FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR;BYMONTH=1,6;BYSETPOS=1
but BYSETPOS reduces the set down to January only. I think splitting it out into multiple rrules would work, but it would greatly increase the complexity of this area of my app so I was hoping for one rrule with a yearly freq.
Thanks!
You could try:
FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1;BYMONTH=<SELECTED_MONTHS_FROM_UI>
Please note the order of options is different.

iCalendar (RFC5545) recurrence rule multiple times a day

How can I make an event occur multiple times a day using the RRULE specified in RFC5545?
Lets say I would like an event to happen every other week on Monday and Friday at 11AM and 18PM. Is it possible to format the RRULE like something as the following:
RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,FR;[TIMES=110000,180000]
Thanks
you have to use the byhour
The BYHOUR rule part specifies a COMMA-
separated list of hours of the day. Valid values are 0 to 23.
so that would be :
RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,FR;BYHOUR=11,18

How to insert forever repeated events in sqlite3 iphone database?

I have one iphone application in which recurring events happens.the duration are like every day,every 2nd day,every 3rd day..,every week on mon,every week on tues,...,every second week on mon,..,every month on 1sr,every month on 2nd...,every second month on 1st,every second month on 2nd,... For some events there is end date but some events occurs forever.so how can i insert them automatically in sqlite3 database.eg.If an event repeats every 3rd day.how can i store it automatically after 3 days.or should i store all the events at the time of creation.If i store all the evnets at time of creation then the events that repeats forever.upto what duration i should store the value of them in database.
For this i have thought 2 approaches.one is storing just one occurance with repeated duration like every day.but in my application edit and delete functionality is also there.suppose event has one field event description then it can be different for different dates if user edit the events.events are displayed datewise on screen for a particular month and user can navigate to any previous and next month for current ,next and previous years.So if i use only single occurance then where should those edited or deleted events should be stored.
And if i take second approach store each occurance in database.Then upto what duration i should store the events which has no enddate.or is there a way that insert is automatically performed after specified duration.
Two ways, one an easy hack, one more difficult but correct :)
(1) Store each individual event for the next 10 years or so (or however long you want to!)
Good :
Easy and quick to implement
Bad :
Your db will get big very quickly.
What if the user wants to edit the details - how do you edit all of them at once?
What if the user wants to cancel / move the event- you have to delete all of them!
(2) Store some sort of 'event recurrence' information in the database with each event i.e. 'Every tuesday'
Good :
Only one event in the database, regardless of how many times it repeats.
Easy for the user to edit / delete the event - there's only one row in the database.
Bad:
More complicated event object - each event must have a list of 'when this event happens' information.
Makes very complicated event timings hard - i.e. 'last friday of every month'
Takes longer to implement
EDIT : My personal choice
I would choose option (2) - it takes longer to implement but I think option (1) will et you into trouble in the future.
I would have a data model like
Event has many Occurances
where your Event is the thing that the user has created with a description, start date etc and an Occurance is some sort of object that will say 'every friday' or 'not on the 4th'.
As part of creating an event, the user will say 'occurs once on Friday 13th' or 'occurs every Wednesday'. That information is used to create an array of Occurance objects.
Occurance would be a protocol that simply has the method occursOn: so you can have lots of different types of occurance (and you can add new types as your app gets more complicated).
The Event object would have a method something like occursOn: where you give it an NSDate and it returns if it occurs on that day. It does this by asking each of it's occurances in turn to see if they apply to that day.
To deal with deleted events, just add an Occurance to the end of the Event's array that overrides the others - i.e. 'not on Friday 13th'.
For example :
(1)
A user creates an event called 'My Event' starting on 1st Jan, occurring every Friday.
Your app would store
Event
description : 'My Event',
start date : 1st Jan 2011
occurances :
WeeklyOccurance
day : Friday
where WeeklyOccurance implements the <Occurance> protocol
(2)
The user asks to show the week's events, starting on Sunday the 8th Jan 2011
The app would :
For each day in the week
For each event in the database
if occursOn: this day
show the event on the ui
and for our event 'My Event', it would implement occursOn: like
- (BOOL)occursOn:(NSDate *)date
is this date before this event starts
if it is, return NO
set remembered = NO
for each occurance
does this occurance say 'yes','no' or '?' for this date?
if 'yes' set remembered YES
if 'no' return NO
if '?' continue the loop
return remembered
Because WeeklyOccurace only knows that it occurs on Fridays, it would return 'yes' for Fridays and '?' for all other days so the ui would show 'My Event' on Friday and not on any other days.
To add different types of occurance, just implement the <Occurance> protocol in different ways.
(3)
The user says actually it should be on every Friday apart from the 22nd
The app would create another Occurance, this time a NotOnThisDayOccurance and add it to the end of the Event's array i.e.
Event
description : 'My Event',
start date : 1st Jan 2011
occurances :
WeeklyOccurance
day : Friday
NotOnThisDayOccurance
day: 22nd Jan 2011
Now, if the users asks to display the weekly events, 'My Event' would look do this :
Ask the WeeklyOccurance if it's valid for friday the 22nd - this would return yes.
Ask the NotOnThisDayOccurance if it's valid for friday the 22nd - this would override the previous result and say NO
Therefore, the event would not show up on the 22nd but would show up on all the other fridays.