Reputation: 379
I am working on an application which needs scheduling (just like the one present in microsoft outlook meeting recurrence) feature. Where we can schedule the job daily, weekly, monthly and yearly and have variations under each schedule (e.g every second monday of month or every alternate monday of week etc).
It should basically work like it does in Microsoft Outlook meeting scheduling.
Any pointers, links, suggestions or any apis available that i could use to implement this logic will be of great help
Thanks
Upvotes: 0
Views: 1269
Reputation: 14163
I recently worked on something similar, the main issue was finding the first day of the current week, from there it was relatively easy to find the day of the week required, and the other issue was finding the first day of the next month.
Here is the code to get
start of the next month (the 1st of the following month)
import java.util.Calendar;
import java.util.Date;
// ...
public static long getWeekStart()
{
//INIT Date
Calendar cal = Calendar.getInstance();
cal.clear(Calendar.HOUR_OF_DAY);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
//get start of this week in milliseconds
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
return cal.getTime().getTime();
}
public static long getNextWeek()
{
//INIT Date
Calendar cal = Calendar.getInstance();
cal.clear(Calendar.HOUR_OF_DAY);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
//get start of this week in milliseconds
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
// start of the next week
cal.add(Calendar.WEEK_OF_YEAR, 1);
return cal.getTime().getTime();
}
public static long getNxtMonthStart()
{
Calendar cal = Calendar.getInstance();
cal.clear(Calendar.HOUR_OF_DAY);
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
// get start of the month
cal.set(Calendar.DAY_OF_MONTH, 1);
// get start of the next month
cal.add(Calendar.MONTH, 1);
return cal.getTime().getTime();
}
Hope this helps with getting the days of the week.
Upvotes: 0