Java Calendar Day isTodayOff(String days, Calendar calendar)

Here you can find the source of isTodayOff(String days, Calendar calendar)

Description

This method is used to check whether the day passed as parameter is an off day.

License

Open Source License

Parameter

Parameter Description
days - Off days for the department.
calendar - The calendar instance of the day which is used to check for off days.

Return

isOff - true or false depending on whether it is off day or not.

Declaration

public static Boolean isTodayOff(String days, Calendar calendar) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    /**/*from  w  ww  . j  av  a  2 s  . c o  m*/
     * This method is used to check whether the day passed as parameter is an
     * off day.
     * 
     * @param days -
     *            Off days for the department.
     * @param calendar -
     *            The calendar instance of the day which is used to check for
     *            off days.
     * @return isOff - true or false depending on whether it is off day or not.
     */
    public static Boolean isTodayOff(String days, Calendar calendar) {

        Boolean isOff = false;

        Integer today = 0;
        today = calendar.get(Calendar.DAY_OF_WEEK); // This is default value

        switch (today) {
        case Calendar.SUNDAY:
            if (days.contains("SU")) {
                isOff = true;
            }
            break;
        case Calendar.MONDAY:
            if (days.contains("MO")) {
                isOff = true;
            }
            break;
        case Calendar.TUESDAY:
            if (days.contains("TU")) {
                isOff = true;
            }
            break;

        case Calendar.WEDNESDAY:
            if (days.contains("WE")) {
                isOff = true;
            }
            break;
        case Calendar.THURSDAY:
            if (days.contains("TH")) {
                isOff = true;
            }
            break;
        case Calendar.FRIDAY:
            if (days.contains("FR")) {
                isOff = true;
            }
            break;
        case Calendar.SATURDAY:
            if (days.contains("SA")) {
                isOff = true;
            }
            break;

        default:
            // throw Business exceptions.
        }

        return isOff;

    }
}

Related

  1. isSunday(GregorianCalendar date)
  2. isTheSameDay(Calendar dayOne, Calendar dayTwo)
  3. isToday(Calendar creationDate)
  4. isToday(Calendar date)
  5. isToday(Calendar now, Calendar then)
  6. isWithinDaysFuture(Calendar cal, int days)
  7. julianDay(Calendar calendar)
  8. minOfDay(Calendar calendar)
  9. moveToCalendarDay(Calendar cal, int day)