Grokking Android

Getting Down to the Nitty Gritty of Android Development

iCal’s Recurrence Rule and Duration Formats

By 6 Comments

If you create repeating events in Android using the CalendarContract content provider, the fields for recurrence rules (RRULE) and durations (DURATION) follow the iCal format (RFC 5545). Here I cover the basics of these formats to create valid field values.

This post is somewhat of an oddity on this blog as most of its content is not Android specific.

Recurrence Rule

The recurrence rule is used in Android whenever you deal with events of the CalendarContract content provider. The event table has the column RRULE that takes the recurrence rule as a String value.

This rule is made up of several components that are separated by semicolons.

As the first element every recurrence rule must define the frequency. It covers all intervals from seconds to years. You use the FREQ qualifier to do so, e.g. FREQ=DAILY.

All other elements are optional. To limit the number of events you can specify the interval, the number of occurrences or the enddate. A FREQ=WEEKLY and a INTERVAL=2 would result in a biweekly event. The number of occurrences is given by the COUNT=x qualifier. And finally an enddate can be given using the element UNTIL=yyyymmdd.

It is also possible for you to select certain elements. E.g. a BYDAY=TU would select Tuesdays, a BYMONTH=5 would select May.

There is another obscure but interesting element: BYSETPOS. This is used to denote one element in a set of elements. A BYSETPOS=1 selects the first element – a BYSETPOS=-1 selects the last element. You have to use it together with another BYxyz element.

Some RRULE samples

As I have already mentioned in my post about the CalendarContract content provider the in and outs of the recurrence rule are pretty tedious and unnecessary complex. Most often you do not need to know all the details. The following samples should help you get to grips with most of the rules.

If you are really into this, have a look at this enormous list of recurrence rules samples.


The format of the duration element is much easier to grasp. It takes only one page of the spec compared to seven for the recurrence rule.

So let’s me show you one duration value and explain the format with this example as a basis:


The first thing, you will notice is the plus sign. Surprisingly durations can have a positive or negative value. The positive value is the default and thus the “+” sign can be omitted. Negative durations can be used to trigger alarms before the event starts. But Android uses a fixed time for this so negative values aren’t used on Android.

The next element after the sign is the “P” which is a fixed constant.

And lastly follows a non-separated string of time quantifiers that all are added up to form the duration.

So the sample given above is for five weeks and three days. What’s odd with durations in the spec is that the biggest period is weeks. It’s not possible to specify months or years.

Time qualifiers
Qualifier Meaning
W Week
D Day
H Hour
M Minute
S Second

Since Android doesn’t use durations for the length of an event, durations usually consist of weeks and days only.


I have covered the basics of the RRULE and DURATION elements of CalendarContracts event table. Since these rules are in a somewhat obscure format I have given you some samples of how they are created. This should get you started whenever you need to create recurring events in your code.

Wolfram Rittmeyer lives in Germany and has been developing with Java for many years.

In recent years he shifted his attention to Android and blogs about anything interesting that came up while developing for Android.

You can find him on Google+ and Twitter.

6 thoughts on “iCal’s Recurrence Rule and Duration Formats”

  1. Thanks a lot for giving a clear tutorial for this.

  2. Ali Reza Barkhordari

    Thanks, It was very helpful for me

  3. For your mother’s day example: Why did you include a count? Is that only going to get the next two mother’s days? Thanks!

    1. Yes, any event with this rule would only take place at the next three occurrences.

  4. Wanted to know that what change the recursive rule will have in the JSON file when I delete one of the scheduled dates from between ?

  5. I had to add “RRULE:” in front of the rules to make it work.

    With IceCube in Ruby:


    examples.each { |e| puts e; p IceCube::Schedule.from_ical(“RRULE:” + e).first(10); puts }

    [2016-12-27 16:30:31 -0800, 2016-12-28 16:30:31 -0800, 2016-12-29 16:30:31 -0800, 2016-12-30 16:30:31 -0800, 2017-01-02 16:30:31 -0800, 2017-01-03 16:30:31 -0800, 2017-01-04 16:30:31 -0800, 2017-01-05 16:30:31 -0800, 2017-01-06 16:30:31 -0800, 2017-01-09 16:30:31 -0800]

    [2017-03-26 16:30:31 -0700, 2018-03-25 16:30:31 -0700]

    [2017-05-14 16:30:31 -0700, 2018-05-13 16:30:31 -0700, 2019-05-12 16:30:31 -0700]

    [2020-11-03 16:30:31 -0800, 2024-11-05 16:30:31 -0800, 2028-11-07 16:30:31 -0800, 2032-11-02 16:30:31 -0700, 2036-11-04 16:30:31 -0800, 2040-11-06 16:30:31 -0800, 2044-11-08 16:30:31 -0800, 2048-11-03 16:30:31 -0800, 2052-11-05 16:30:31 -0800, 2056-11-07 16:30:31 -0800]


Leave a Reply

Your email address will not be published. Required fields are marked *