for some reason, I am unable to figure how to code it in a clean way.
I have a task object and this object has a start date and end date. I want to pass this object to method that will take this task, clone it X number of times according to the frequency and set its start date to the occurance date.
Offcourse, things can be much better illustrated by examples:
So lets say I have task that has start date of June 1 ,2012 and end date of September 15, 2012. The frequency is set to monthly. I want to pass this task to a method that would create an array of 4 tasks for me (June, July, Aug, September) of whose the start date is set to the first of the respective month
ArrayList<task> spawnTasks(Task task, Frequency Monthly){
ArrayList<Task> arr = new ArrayList<Task>();
Task TaskJune = task.clone();
TaskJune.setStartDate("June, 1, 2012");
Task TaskJuly = task.clone();
TaskJuly.setStartDate("July, 1, 2012");
Task TaskAug = task.clone();
Taskaug.setStartDate("Aug, 1, 2012");
Task TaskSept = task.clone();
TaskSept.setStartDate("Sept, 1, 2012");
}
So as you can see I created the task once a month because frequency is monthly ( I can have biweekly or monthly only) and it happened on the 1st because thats the start date and it never exceeded september because the enddate is sept 15.
I know I have to use Calendar and loop to do it but I just can’t figure it out
Try this: