-
Notifications
You must be signed in to change notification settings - Fork 16
Building a recurrence
maltaisn edited this page Oct 18, 2019
·
1 revision
Recurrence
objects can be created with constructor-like syntax in 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:
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.