1

I've been trying to figure out how to compose an RRULE that has events on alternating days each week; for example:

  • Week A: Monday at 4pm
  • Week B: Friday at 4pm

Where Week A and Week B alternate continuously into the future.

The closest I've gotten is this:

RRULE:FREQ=WEEKLY;COUNT=30;INTERVAL=2;BYDAY=MO,FR

which is close, but gives me the monday and friday on the same week. How can I code it to select the second friday in the two-week interval? This seems much less complex than much of what can be done with RRULEs, so I'm likely missing something obvious?

marcus erronius
  • 3,613
  • 1
  • 16
  • 32

2 Answers2

1

If this is intended to go on forever, with no 'COUNT', then I think the only way you can do it is to have two events.

Using any other of the BY's even BYSETPOS gets one into trouble at some point at the end of the year, or the end of the sequence as far as you defined it. Two events allows one to iterate the Monday and the Friday cleanly.

The choice of DTSTART for each event is crucial to be sure that you are recurring the right Fridays after the Mondays. You have something like M fm FM fm FM fm

From https://calendar.google.com/calendar/ical/eppua87dpfnq85bsrrt2siqlcs%40group.calendar.google.com/public/basic.ics

BEGIN:VEVENT
DTSTART:20211022T160000Z
DTEND:20211022T170000Z
RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=2;BYDAY=FR
DTSTAMP:20211012T064353Z
UID:STACKTESTFRIDAY
CREATED:20171102T185254Z
DESCRIPTION:
LAST-MODIFIED:20211012T064141Z
LOCATION:
SEQUENCE:2
STATUS:CONFIRMED
SUMMARY:Afternoon Tea on Friday
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART:20211011T160000Z
DTEND:20211011T180000Z
RRULE:FREQ=WEEKLY;WKST=MO;INTERVAL=2;BYDAY=MO
DTSTAMP:20211012T064353Z
UID:STACKTESTMONDAY
CREATED:20171102T185254Z
DESCRIPTION:
LAST-MODIFIED:20211012T064112Z
LOCATION:
SEQUENCE:2
STATUS:CONFIRMED
SUMMARY:Afternoon Tea on Monday
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
anmari
  • 3,830
  • 1
  • 15
  • 15
  • Any chance you could expand on/link to information about what you said about BYSETPOS possibly causing trouble at he end of the sequence? Also, thanks for the answer, I'm choosing this one since it seems the most correct to me, and seems like pretty good evidence that it isn't possible with one event. – marcus erronius Oct 18 '21 at 22:58
  • 1
    Iterate the sets & check the year ends/starts EG: FREQ=YEARLY BYDAY=MO,FR & BYSETPOS to pick the alternating MOs & FRs IF you define your BYSETPOS from say 1 Jan 2024 with week A and week B, then the list of BYSETPOS starts 1,4,5,8,9 etc. HOWEVER that BYSETPOS list doesn't work for 2025. The first Week A (NB ISO definition of week #) doesn't have a MO in 2025, The BYSETPOS for 2025 would be something like 1,2,5,6 etc One can't use BYSETPOS with a yearly FREQ See https://docs.google.com/spreadsheets/d/1QrasGan46Iu3kSQ7V9rfjka2vw22RR_EjtkOm0YgLsA/edit?usp=sharing – anmari Oct 19 '21 at 10:18
1

Here another option that might work for you. In a YEARLY rule you can prepend the BYDAY elements with an offset n to identify the n-th instance of that weekday in the year.

If your recurring event starts on the 20th Monday of the year you could build a rule like this to iterate 30 instances with alternating weekdays.

RRULE:FREQ=YEARLY;BYDAY=20MO,21FR,22MO,23FR,24MO,25FR,26MO,27FR,28MO,29FR,30MO,31FR,32MO,33FR,34MO,35FR,36MO,37FR,38MO,39FR,40MO,41FR,42MO,43FR,44MO,45FR,46MO,47FR,48MO,49FR

Note, this assumes the year starts on a Saturday, Sunday or Monday.

If the year starts on a Tuesday, Wednesday, Thursday or Friday, the weekdays have to have the same number (because in that case the n-th Monday and the n+1-th Friday occur in the same week), i.e.

RRULE:FREQ=YEARLY;BYDAY=20MO,22FR,22MO,24FR,24MO,26FR,26MO,28FR,28MO,30FR,30MO,32FR,32MO,34FR,34MO,36FR,36MO,38FR,38MO,40FR,40MO,42FR,42MO,44FR,44MO,46FR,46MO,48FR,48MO,50FR
Marten
  • 3,802
  • 1
  • 17
  • 26
  • Marten, what happens on the year rollover? Sometimes there are 53 weeks in a year and sometimes 52 weeks in a year. For benefit of anyone else reading this, please be aware that the ICS week no is NOT the same as what people may conventionally expect a week number to be. More info: https://icalevents.com/2559-week-numbers-and-week-starts/ – anmari Oct 12 '21 at 21:35
  • I should point out, that the index numbers in `BYDAY` are the n-th occurrence of that day in the calendar year, **not** week numbers, e.g. the 1st Friday (`1FR`) of a year could belong the last calendar week of the previous year. On year rollover you may have to adjust the alternation pattern, i.e. switch from the first type to the second one or vice versa. This has to be carefully adjusted to every year and in general this can not be applied to more than 52 weeks in a row, because only in few cases the pattern will be the same for two consecutive years. – Marten Oct 14 '21 at 20:35
  • I'm certain, however, that it takes just two recurrence rules to generate the `BYDAY` values for a given start date. The first one generates Mondays two week apart (i.e. `FREQ=WEEKLY;INTERVAL=2;BYDAY=MO` and the second one generates the Monday and Friday events (11 days apart) for each 2-week cycle (i.e. `FREQ=DAILY;INTERVAL=11;COUNT=2`) for each of the dates generated by the first rule. At present this can not be expressed in a `VEVENT` but it might be possible once [iCalendar Series](https://datatracker.ietf.org/doc/html/draft-ietf-calext-icalendar-series) has been standardized. – Marten Oct 14 '21 at 20:42