Java Week Calculate getWeeksAddCount(int repType, int repIndex)

Here you can find the source of getWeeksAddCount(int repType, int repIndex)

Description

Gets count of weeks to add, when repetition was chosen.

License

Apache License

Parameter

Parameter Description
repType Type of repetition.
repIndex Index of repetition (defacto FOR cycle).

Return

int Count of weeks to add.

Declaration

public static int getWeeksAddCount(int repType, int repIndex) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This file is part of the EEG-database project
 * /*from  ww  w  .j  a v a 2s.  c o  m*/
 *   ==========================================
 *  
 *   Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/)
 *  
 *  ***********************************************************************************************************************
 *  
 *   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.
 *  
 *  ***********************************************************************************************************************
 *  
 *   BookingRoomUtils.java, 2013/10/02 00:01 Jakub Rinkes
 ******************************************************************************/

import java.util.*;

public class Main {
    /**
     * Gets count of weeks to add, when repetition was chosen.
     *
     * @param repType  Type of repetition.
     * @param repIndex Index of repetition (defacto FOR cycle).
     * @return int Count of weeks to add.
     */
    public static int getWeeksAddCount(int repType, int repIndex) {
        int weekNum = new GregorianCalendar().get(Calendar.WEEK_OF_YEAR);

        int add = 0;
        if (repType == 0)
            add = 1;
        if ((repType == 1 && weekNum % 2 == 1) || (repType == 2 && weekNum % 2 == 0)) {
            add = 2;
        }
        if ((repType == 1 && weekNum % 2 == 0) || (repType == 2 && weekNum % 2 == 1)) {
            if (repIndex == 0) {
                add = 1;
            } else {
                add = 2;
            }
        }
        return add;
    }
}

Related

  1. getWeek(Date date)
  2. getWeekAbscissa(Class cls)
  3. getWeekNumberFromDate(Date date)
  4. getWeekOfDate(Date date)
  5. getWeekOfYear(Date date, Locale locale)
  6. getWeeksInYear(int year)
  7. isSameWeekDates(Date date1, Date date2)
  8. nextWeek(Date date, int week)
  9. nextWeek(long date)