Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:30:47+00:00 2026-06-14T03:30:47+00:00

for some reason, I am unable to figure how to code it in a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:30:48+00:00Added an answer on June 14, 2026 at 3:30 am

    Try this:

    private List<Task> spawn(Task original, Frequency frequency) {
    
        Date sd = original.getSd();
        Date ed = original.getEd();
    
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(sd.getTime());
    
        List<Task> tasks = new ArrayList<Task>();
        for (; cal.getTimeInMillis() <= ed.getTime(); cal.add(frequency.getFrequency(), frequency.getMultiplier())) {
            Task task = original.clone();
            task.setSd(cal.getTime());
    
            tasks.add(task);
        }
    
        return tasks;
    }
    
    public enum Frequency {
    
        WEEKLY(Calendar.WEEK_OF_YEAR, 1),
        BIWEEKLY(Calendar.WEEK_OF_YEAR, 2),
        MONTHLY(Calendar.MONTH, 1),
        QUARTERLY(Calendar.MONTH, 3);
    
        private int frequency;
        private int multiplier;
    
        Frequency(int frequency, int multiplier) {
            this.frequency = frequency;
            this.multiplier = multiplier;
        }
    
        public int getFrequency() {
            return frequency;
        }
    
        public int getMultiplier() {
            return multiplier;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason that I cannot figure out, when I put the code in
I have good familiarity with CSS but for some reason I am unable to
For some reason im unable to solve this. what will be the Big-o Notation
For some reason i am unable to save HABTM relationships, I have checked the
Okay, for some reason this morning, I am unable to connect to the Wordpress
I'm guessing this is very simple, but for some reason I am unable to
For some reason I seem unable to use JSON.stringify on a DOMWindow object. For
For some reason this isn't working, am I missing something obvious? RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html
This is a trivial question, but for some reason I am having trouble with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.