1

I am mapping the following set of recurrence rules to RFC5545 RRULEs (to create Google Calendar events):

  • Never
  • Daily
  • Weekly
  • EveryOtherWeek
  • TwiceAMonth
  • Every4Weeks
  • Monthly
  • EveryOtherMonth
  • Every3Months
  • Every4Months
  • TwiceAYear
  • Yearly
  • EveryOtherYear

Some of these are easier than others (consider Every4Weeks vs TwiceAMonth) and are already implemented.


Assuming this can be expressed in an RRULE and I have a start date of 2017/08/24 (if start date is relevant) what would my RRULE need to be to satisfy, for example, TwiceAMonth?


Bonus: If anyone comes up with RRULEs for "every other week", "twice a year", etc. I would be eternally grateful.

1 Answer 1

6

To code an RRULE one needs to get very specific. 'Twice a week/month/year' - if you said that to a human, would they be able to work out exactly which days for 2019?

Every sequence needs a DTSTART, and it is definitely needed for a recurring sequence that depends on or is determined by that date. EG: every other week would need a day to start on, and could recur every 14 days or every 2 weeks. Twice a month: which days? is day of week relevant? are days determined by start or end of month?

You have at your disposal combinations of FREQ, INTERVAL, and all the 'BY's BYDAY, BYMONTHDAY, BYSETPOS etc. Some 'expand' the number of days and some 'limit' the number of days.

The spec itself has some examples https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html. Here are some more examples:

Twice a month on the 1st and the 15th

RRULE:FREQ=MONTHLY;BYMONTHDAY=1,15

Twice a month on the first and third thursday

DTSTART;TZID=America/New_York:20170824T000000
RRULE:FREQ=MONTHLY;BYDAY=1TH,3TH

Every other week starting from 24th Aug 2018

DTSTART;TZID=America/New_York:20170824T000000
RRULE:FREQ=WEEKLY;INTERVAL=2

Twice a year on the 2nd to last day of Feb and August

RRULE:FREQ=YEARLY;BYMONTHDAY=-2;BYMONTH=2,8

Twice a year on the last day and the 50th day

RRULE:FREQ=YEARLY;BYSETPOS=-1,50

There are many possible combinations. https://icalevents.com/2447-need-to-know-the-possible-combinations-for-repeating-dates-an-ical-cheatsheet/

4
  • Thank you for your response! I was hoping I could get away with not explicitly specifying days (hoping the server would do so given a start date), seems I have more work ahead of me.
    – taryn
    Jan 7, 2019 at 13:42
  • The rules can given a startdate, as per examples above, it depends what the rules are though, and the rules depend on what dates are acceptable. I'm intrigued as to what the purpose of this is - would random dates from the server truly be acceptable? EG: if twice a year came back as Jan 1 and Jan 2 every year would that be acceptable?
    – anmari
    Jan 8, 2019 at 0:18
  • If your rule for twice a year was every 6 month from a startdate that would work. It all depends what the purpose is then you can determine the rule that makes sense.
    – anmari
    Jan 8, 2019 at 0:25
  • You just saved me 2 days of coding. I was about to have to try to figure out the 3rd week number in each month for thursday, this notation works correctly! FREQ=MONTHLY;BYDAY=3TH
    – moto_geek
    Dec 2, 2019 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.