8

I have calendar view where I'm setting events but I don't have idea how to handle with recurring events. I'm getting value of Event.RRULE by cursor:

String rrule = cursor.getString(cursor.getColumnIndex(Events.RRULE));

For example rrule value is:

FREQ=WEEKLY;BYDAY=MO,WE,FR;INTERVAL=1
FREQ=MONTHLY;BYMONTHDAY=6;INTERVAL=2

How can I get values from this string to set them as Calendar values?

For example I want get Monday - MO to set it in Calendar object

Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
Artur Gniewowski
  • 470
  • 7
  • 17

1 Answers1

4

There are different libraries to handle RRULEs. You can use google-rfc-2445

import com.google.ical.values.RRule;
//...
RRule rule = new RRule("RRULE:FREQ=MONTHLY;BYMONTHDAY=6;INTERVAL=2");

and than use properties for created object in useful way, or you could use lib-recur

import org.dmfs.rfc5545.recur.RecurrenceRule;
// ...
RecurrenceRule rule = new RecurrenceRule("FREQ=MONTHLY;BYMONTHDAY=6;INTERVAL=2");

and use parsed properties from rule object.

Sergii
  • 7,044
  • 14
  • 58
  • 116
  • This rule object will set on calendar object? – Shashank Priyadarshi Jun 18 '20 at 02:55
  • @ShashankPriyadarshi, Rule describes event behavior which belongs to calendar. The rule can't exist without event, so it belongs to event. Also we can say rule belongs to calendar, because event belongs to calendar (following RFC-5545). Possible your question was about `java.util.Calendar`, in last case - doesn't. – Sergii Jun 18 '20 at 08:57