3
votes

I am working on a calendar app and trying to schedule recurring events.

My biggest issues arise when it comes to events that are supposed to be scheduled on a monthly basis. like day-15 of every month.

Methods like :

Calendar.getInstance();
Calendar.MONTH;
date.setMonth(date.getMonth() + 1);
DateUtils.addMonths(new Date(), 1);

all seem to be not supported by Codename One.

Using date.getTime() appears not to be the best approach. Is there any other way to schedule recurring events in CN1?

Many thanks in advance.

1

1 Answers

2
votes

Yes, you can increase the month by using just the Calendar class.

Similar to above is:

java.util.Calendar cal = java.util.Calendar.getInstance();

//first check if current month is December, if it is then switch to a new year
if (cal.get(java.util.Calendar.MONTH) == 11) {
    cal.set(java.util.Calendar.YEAR, cal.get(java.util.Calendar.YEAR) + 1); //increase the year
    cal.set(java.util.Calendar.MONTH, 0); //January = 0
} else {
    cal.set(java.util.Calendar.MONTH, cal.get(java.util.Calendar.MONTH) + 1);//increase the month
}