# Intro to recurring events I want to show you a few things I've learned during cooldown about how recurring calendar rules work in existing calendar software. This build cycle we'll be building some features to support recurring 1-on-1s so it will be important that we have some understanding about how this might work. I want to run you through some of the concepts involved—and also show a few of the standards and code libraries that could help us out. - Intro to recurring events - What kind of recurrence rules do we need to support? - What are some of the standards around this? ## Getting started Scheduling an event that repeats is a pretty common thing we do in our calendars. You would've seen options like these in your calendar software: ![Apple calendar](https://i.imgur.com/9Eqk1Yy.png =250x) ![Google calendar](https://i.imgur.com/2lyiuot.png =250x) Let's take a look at some common use-cases and how this can work... ## What kind of recurrence rules might you want to support Some basic cases: - Daily - Weekly - Monthly Ok, how about more advanced cases? - Every 2 weeks - Second Wednesday of the Month - First Friday of the Month - Every day except Christmas - Every Easter..? ## What are some of the standards around this? ### ISO 8601 - ISO 8601 is a pretty great standard for representing date and time formats. - But only handles basic recurrence cases: [link](https://i.imgur.com/Pxl74NL.png) ### iCalendar specification [RFC 5545](https://www.google.com/url?q=http://tools.ietf.org/html/rfc5545&sa=D&source=calendar&ust=1595607714083000&usg=AOvVaw2mPBzHUwmArP9l8QYTxqsc) - A standard that's designed to handle pretty much everything you would want to do in a calendar - Important part: the **RRULE** - RRULE is short for Recurrence Rule .. it describes how things repeat - Usually for events.. but also can be applied to todo's and also to represent when timezones shift due to daylight savings.. kind of cool! - We only really care about repeating events right now though. ## A demo of some of the things you can do with <u>RRULE</u> ### Basic examples Something that happens every day: RRULE:FREQ=DAILY You have to combine the RRULE with a start date and time so you can figure out when the next one will happen: DTSTART;TZID=AEST:20200717T153000 RRULE:FREQ=MONTHLY ... the DTSTART has the timezone as well as the date and time all combined together. ### Timezones and daylight savings The timezone is important for dealing with daylight savings. When daylight savings kicks in.. we generally expect repeating events to stay at the same local time. e.g. For the daily standup event. It's always at 10am Melbourne time — even if that means in San Francisco it's moving from 5pm to 4pm. The RRULE can also specify a number of instances or an end time RRULE:FREQ=DAILY;COUNT=10; RRULE:FREQ=DAILY;UNTIL=20150919T063000Z Every workday RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR ### Exceptions to the rule The iCal RRULE allows for exceptions, you can exclude an occurance by specifying the time with EXDATE: DTSTART;TZID=AEST:20200717T153000 RRULE:FREQ=MONTHLY EXDATE;TZID=AEDT:20201117T153000 You can also add in extra occurences that don't fit in with the usual schedule using RDATE: DTSTART;TZID=AEST:20200717T153000 RRULE:FREQ=MONTHLY RDATE;TZID=AEDT:20201010T184500 Sometimes you might not want the first occurence to be included, so you can exclude it. e.g. every Friday the 13th DTSTART;TZID=Australia/Melbourne:20200720T090000 EXDATE;TZID=Australia/Melbourne:20200720T090000 RRULE:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13 ### Cancelling and modifying events So with these you can start to represent things like one-off cancellations. You can also allow users to edit the time on a specific meeting. ![](https://i.imgur.com/kiB0jXl.png =250x) Editing the time of a specific event can be represented by excluding one date.. and then adding a new one. DTSTART;TZID=AEST:20190114T180000 RRULE:FREQ=MONTHLY EXDATE;TZID=AEDT:20201014T180000 RDATE;TZID=AEDT: 20201014T183000 ## What formats do the Google Calendar API and others already use? - Google / Apple support iCal RRULEs - Partial iCal support by Microsoft Outlook .. they have their own thing ## A quick tour of some code libraries for dealing with RRULEs: - The [ice_cube](https://github.com/seejohnrun/ice_cube) ruby gem - The [rrule.js](http://jakubroztocil.github.io/rrule/) library for frontend - challenge: browser timezone support is not good ## Links [https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html](https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html) [https://github.com/seejohnrun/ice_cube](https://github.com/seejohnrun/ice_cube) [https://github.com/jakubroztocil/rrule](https://github.com/jakubroztocil/rrule) [http://jakubroztocil.github.io/rrule/](http://jakubroztocil.github.io/rrule/) ## Questions!