Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle with Events.RRULE

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);
like image 634
Artur Gniewowski Avatar asked Feb 07 '17 20:02

Artur Gniewowski


1 Answers

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.

like image 172
Sergii Avatar answered Nov 08 '22 22:11

Sergii