Java Calendar Add addWeekdays(Calendar cal, int days)

Here you can find the source of addWeekdays(Calendar cal, int days)

Description

add Weekdays

License

Apache License

Declaration

private static void addWeekdays(Calendar cal, int days) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2011 Matt Burns//from www .j  av  a 2s.c om
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

import java.util.Calendar;

public class Main {
    private static void addWeekdays(Calendar cal, int days) {
        // This looks crazy to me but I can't seem to describe the same
        // functionality in a clear way...
        while (days > 0) {
            while (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
                    || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                cal.add(Calendar.DATE, 1);
            }
            cal.add(Calendar.DATE, 1);
            days--;
            while (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
                    || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                cal.add(Calendar.DATE, 1);
            }
        }
    }
}

Related

  1. addMilliseconds(Calendar calendar, Long amount)
  2. addMonth(Calendar cal, int period)
  3. addMonthDayToCal(Calendar cal, int month, int day)
  4. addSeconds(Calendar calendar, int amount)
  5. addToUTCMilliSeconds(int calendarTime, int actualValue)
  6. addWorkdays(final Calendar calendar, final int dauer)
  7. appendDate(StringBuffer buf, Calendar cal)
  8. appendDate(StringBuffer dateString, Calendar calendar)
  9. appendDate(StringBuffer sb, Calendar cal)