Is it possible to have an OR expression in a iCalendar RFC5545 recurrence rule? - icalendar

I'm currently using iCalendar specification (RFC 5545) to deal with recurring events.
Until yesterday, their recurrence rules covered all my needs, but now I'm having a hard time implementing the following rule:
Every month on the first Monday OR Wednesday of the month.
Ex:
2021-05-01 is Saturday: the event will happen on Monday 2021-05-03.
2021-06-01 is Tuesday: the event will happen on Wednesday 2021-06-02.
2021-07-01 is Thursday: the event will happen on Monday 2021-07-05.
2021-08-01 is Sunday: the event will happen on Monday 2021-08-02.
Is there a way to define this kind of "conditional" rule?

If I understand the requirement correctly, it is not exactly conditional. It is that ONLY the first of the first Monday and first Wednesday is required. BYSETPOS is aimed at this.
In this example, it is being used to calculate the last working day https://icalevents.com/2555-paydays-last-working-days-and-why-bysetpos-is-useful/
For your example
RRULE:FREQ=MONTHLY;BYDAY=1MO,1WE;BYSETPOS=1
should do the trick,
Basically the RRULE will expand out all the first MONDAY and WEDNESDAYs and then 'contract' ie take the first date of each pair.
Page 43 of the specification https://www.ietf.org/rfc/rfc5545.txt shows the priorities of the 'expansions' and 'contractions'.

Related

RRULE for every other week except last week of month

I need an RRULE for every other Saturday except the last week of the month. I tried to create one with a weekly frequency, but didn't know how to apply an exception for the last week of the month:
RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SA
I also tried creating a rule with a monthly frequency, which allowed me to skip the last week of the month, but I didn't know how to make it every other week:
RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SA;BYSETPOS=-2,-3,-4,-5
I looked through the specification, but I'm not seeing anything that makes this possible.
The secret to the solution here is that BYMONTHDAY can be negative like BYSETPOS. This allows one to exclude the last 7 days of each month even though the number of days in the month varies. Your DTSTART should be on a SATURDAY, so one doesn't really need the BYDAY=SA
This rrule works in google calendar (if DTSTART is on Saturday and generally for any every 2nd week but not the last week rule for any day of week specified by the DTSTART):
RRULE:FREQ=WEEKLY;INTERVAL=2;BYMONTHDAY=-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,-21,-22,-23,-24,-25,-26,-27,-28,-29,-30,-31
See test calendar:
https://calendar.google.com/calendar/u/0?cid=ZXBwdWE4N2RwZm5xODVic3JydDJzaXFsY3NAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ
Spec: https://datatracker.ietf.org/doc/html/rfc2445#page-43
and
https://icalevents.com/2447-need-to-know-the-possible-combinations-for-repeating-dates-an-ical-cheatsheet/ for the expansion & contraction (limiting) rules & combinations

iCalendar repeat rule for x days before the 2nd Tuesday in the month

I have a meeting on every 2nd Tuesday of the month.
I need 10 days to prepare that meeting - this means I would need a recurring event "10 days before the 2nd Tuesday of the month"
(added via ical file)
I found iCalendar repeat rule for "the day after the second monday of the month" but I'm not sure how/if this applies to my situation/how to remodel it to fit my needs.
The issue is that since it's 10 days prior it may even be in the previous month in some cases (e.g. if the first day of the month is a Tuesday)
What is the correct command for this?
EDIT: the time is always from 8-10am just so it can be included.

RRULE for the weekend including the first sunday of a month

We have a event every year on the weekend (Fr-Su) that includes the first Sunday of June. How would I create a iCalendar Event that expresses these three days (whole day events)?
Creating a rule for the first Sunday is easy. But for the Saturday and Friday, I did not succeed to create a rule that counts backwards (RFC 5545 says INTERVAL, COUNT must be positive]. Moreover I could not think of a different expression that would start from the Friday - it could be the last Friday of May, but also the first in June.
The RRRULE specification in RFC 5545 is lacking in this regard. The INTERVAL and COUNT values are for the repeating events, not the event itself. I've come across a similar issue when trying to define the USA day "Black Friday", the day after the 4th Thursday in November (Friday after Thanksgiving). The 4th Friday in November could occur the day after the 4th Thursday, or the prior week. There is not a way that I have found to make a RRULE for this situation.
I believe you will need to code the events individually instead of using a recurring rule.
RRULE:FREQ=YEARLY;BYDAY=FR;BYMONTH=5,6;BYSETPOS=2;BYMONTHDAY=-2,-1,1,2,3,4,5,6,7' seems to do the trick.
How can I write an ICS file for the Friday before the first Saturday of the month? led me to the right track: with 'BYMONTHDAY' I can count backwards from the end of the month.
The Friday before the first Sunday of the next month can be the last or the second to last day of the previous month, or up to the 5th day of the month. If I include May and June, I will get a set that includes the day. 'BYSETPOS' allows me to choose the second of the found Fridays. To always have the second in the set being my desired day, I include the 6th and 7th day of the month, which gives me a stable first Friday in May. Possibly matched additional Fridays in June are discarded by 'BYSETPOS' anyway.
Extending this to Saturday is simple, and the first Sunday of June is trivial.
I developed the rule with rrule.js
https://jakubroztocil.github.io/rrule/#/rfc/RRULE:BYDAY=FR;BYMONTH=5,6;BYSETPOS=2;BYMONTHDAY=-2,-1,1,2,3,4,5,6,7

ICalendar recurring event starts first day of month, ends last day of month, repeats every month

Using rfc5545 is there a way to represent an event that starts on the first day of each month and ends on the last day of each month and repeats every month?
It's slightly different than a daily repeating event which is not ideal for my use case.
short answer: No
This is driven by the fact that the RFC5545 clearly states that an event cannot have a month duration, only days, weeks or seconds.
3.3.6. Duration
[...] Note that unlike
[ISO.8601.2004], this value type doesn't support the "Y" and "M"
designators to specify durations in terms of years and months.
(emphasis mine)

how to set event duration in ekevent in icalender?

I created event in iCalendar. Its start date is today and end date is next month 15th. and this is recurrence type of event . so if set event as recurrence event then changed end date as same as recurrence end date. I want to give time duration of event,like 3.30P.M to 6.30P.M. How to i set event duration ....
"DTSTART;TZID=US-Eastern:19970105T083000
RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9; BYMINUTE=30
First, the "INTERVAL=2" would be applied to "FREQ=YEARLY" to arrive at "every other year".
Then, "BYMONTH=1" would be applied to arrive at "every January, every other year".
Then, "BYDAY=SU" would be applied to arrive at "every Sunday in January, every other year".
Then, "BYHOUR=8,9" would be applied to arrive at "every Sunday in January at 8 AM and 9 AM, every other year".
Then, "BYMINUTE=30" would be applied to arrive at "every Sunday in January at 8:30 AM and 9:30 AM, every other year".
Then, lacking information from RRULE, the second is derived from DTSTART, to end up in "every Sunday in January at 8:30:00 AM and 9:30:00 AM, every other year".
Similarly, if the BYMINUTE, BYHOUR, BYDAY, BYMONTHDAY or BYMONTH rule part were missing, the appropriate minute, hour, day or month would have been retrieved from the "DTSTART" property."
Please any one guide me how to set ...
I know how to recurrence rule is working but my question is how to set event duration.
No client that I know of support BYMINUTE and BYHOUR so unless this event is for your own application consumption, you are asking for trouble. IN any case, the very first instance will use the DTSTART value as the beginning, regardless of what you may have put in BYMINUTE and BYHOUR (see https://www.rfc-editor.org/rfc/rfc5545#section-3.8.5.3)
Then you can use DTEND or DURATION:
DTSTART;TZID=US-Eastern:19970105T083000
DTEND;TZID=US-Eastern:19970105T153000
or
DTSTART;TZID=US-Eastern:19970105T083000
DURATION:PT7H