Skip to content

Building a recurrence

maltaisn edited this page Oct 18, 2019 · 1 revision

Recurrence objects can be created with constructor-like syntax in Kotlin:

Kotlin
val r = Recurrence(Recurrence.Period.MONTHLY) {
    frequency = 3
    setDayOfWeekInMonth(Recurrence.SATURDAY, 4)
    endDate = System.currentTimeMillis()
}

The reference inside the lambda is a Recurrence.Builder. In Java, the builder must be instantiated explicitly which is a bit more verbose:

Java
Recurrence.Builder rb = new Recurrence.Builder(Recurrence.Period.WEEKLY);
rb.setFrequency(2);
rb.setDaysOfWeek(Recurrence.MONDAY, Recurrence.TUESDAY);
rb.setEndCount(6);
Recurrence r = rb.build();

The complete list of properties that can be set on a Recurrence can be found in the docs:

Recurrence objects are immutable and must be created with the builder. The constructor is private. The builder should validate all arguments so that only valid recurrence rules can be built.

Clone this wiki locally