2

Can you specify an RRULE for the following scenario?

Recurring monthly on the first day of each month. Except, if it falls on Sunday, then recurs on the following day (Monday the 2nd of the month). Except, if it falls on Friday, then recurs on the previous day (Friday the last of previous month).

This is just an exercise to see what's possible and how to work around various issues.

I tried setting this up with 3 separate RRULE:

RRULE:FREQ=MONTHLY;BYMONTHDAY=1;BYDAY=MO,TU,WE,TH,FR
RRULE:FREQ=MONTHLY;BYMONTHDAY=2;BYDAY=MO
RRULE:FREQ=MONTHLY;BYSETPOS=-1;BYDAY=FR

The first rule does what I want - the first day of the month only if it falls on weekday. The second rule does what I want - if the first is on Sunday, then this rule picks to following Monday, which is Monday the 2nd of the month. The third rule is the issue. This picks the last Friday of each month. But what I wanted was the last day of the month only if it falls on Friday. Or, said differently, the last Friday of the month only if it is the last day of the month. This is a bit sticky because you can't use BYMONTHDAY since different month has different number of days, and I don't think BYMONTHDAY=-1 works as expected. Can someone come up with the correct rule for "last day of the month only if it is Friday".

Marcus Yoo
  • 121
  • 2

1 Answers1

2

The RFC5545 has a table in 3.3.10 Recurrence Rule which specifies:

  • the dependency of multiple BYxxx and FREQ rule part value.
  • the order in which the BYxxx should be evaluated:
      If multiple BYxxx rule parts are specified, then after evaluating
      the specified FREQ and INTERVAL rule parts, the BYxxx rule parts
      are applied to the current set of evaluated occurrences in the
      following order: BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, BYDAY,
      BYHOUR, BYMINUTE, BYSECOND and BYSETPOS; then COUNT and UNTIL are
      evaluated.

When you put all this together your third RRULE should look like:

RRULE:FREQ=MONTHLY;BYMONTHDAY=-1;BYDAY=FR

Which basically says that any last day of any month which is a Friday will be part of the recurrence set - which to my understanding is your desired result-.

Community
  • 1
  • 1
Auberon Vacher
  • 4,655
  • 1
  • 24
  • 36