Function for returning date after adding x number of business days (no sat, sun)

Function for returning date after adding x number of business days (no sat, sun)

I have a customer that wanted to let a user schedule 4 BUSINESS DAYS out. I couldn't find a saner way to do this so here's my function. 




  1. date helper.bizDays(int days)
  2. {
  3.     iterator = helper.iterator();
  4.     time = zoho.currentdate;
  5.     for each n in iterator
  6.     {
  7.         if (input.days  >  0)
  8.         {
  9.             time = time.addDay(1);
  10.             if (time.getDayOfWeek()  ==  7)
  11.             {
  12.                 time = time.addDay(2);
  13.             }
  14.             else if (time.getDayOfWeek()  ==  1)
  15.             {
  16.                 time = time.addDay(1);
  17.             }
  18.         }
  19.         input.days = (input.days  -  1);
  20.     }
  21.     return time;
  22. }

I wanted to make note that I'm using an "iterator" function that I use all the time for a "while" loop replacement. Zoho doesn't let you do condition based loops because it doesn't want people creating infinite loops. (I think they said they were going to add a while expression because they had the 5k statement limit in place, but they haven't yet)

The iterator is just a list of 0's that can been "for each'd" over. 

  1. list helper.iterator()
  2. {
  3.     i = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  4.     return i;
  5. }