Java Day End isWorkingDay(final Calendar calendar, final Long[] holidays)

Here you can find the source of isWorkingDay(final Calendar calendar, final Long[] holidays)

Description

is Working Day

License

LGPL

Declaration

public static boolean isWorkingDay(final Calendar calendar, final Long[] holidays) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.*;

public class Main {
    /**/* w w  w  .  j a  va  2s.com*/
     * MONTH=2 *
     */
    public static final int MONTH = Calendar.MONTH;
    /**
     * Year=1 *
     */
    public static final int YEAR = Calendar.YEAR;
    /**
     * no-working days
     */
    private static final int[] highDays = { Calendar.SUNDAY, Calendar.SATURDAY };

    /**
     * Return true if the day is a working day
     *
     * @param date     Date
     * @param holidays Array of holidays
     * @return Return true if the day is a working day
     */
    public static boolean isWorkingDay(final Date date, final Long[] holidays) {
        return isWorkingDay(date.getTime(), holidays);
    }

    /**
     * Return true if the day is a working day
     *
     * @param time     Long - time in milliseconds
     * @param holidays Array of holidays
     * @return Return true if the day is a working day
     */
    public static boolean isWorkingDay(final long time, final Long[] holidays) {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);

        return isWorkingDay(calendar, holidays);
    }

    public static boolean isWorkingDay(final Calendar calendar, final Long[] holidays) {

        // check if in holiday
        if (null != holidays) {
            final Calendar holiday = Calendar.getInstance();
            for (final long d : holidays) {
                holiday.setTimeInMillis(d);
                if (holiday.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)
                        && holiday.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)
                        && holiday.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH)) {
                    return false;
                }
            }
        }

        // check day of week
        final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        for (final int i : highDays) {
            if (i == dayOfWeek) {
                return false;
            }
        }

        return true;
    }
}

Related

  1. isNowBetween(Date start, Date end)
  2. isSameDay(Calendar cal1, Calendar cal2)
  3. isSameDay(final Calendar calendar1, final Calendar calendar2)
  4. isTodayWithinPeriod(Date periodStart, Date periodEnd)
  5. isValidSendDate(Date sendDate)
  6. postponeWorkingDay(final Calendar calendar, final int measureUnit, final int amount, final Long[] holidays)
  7. previousWorkingDay(final Calendar calendar, final Long[] holidays)
  8. secondsBetween(Date start, Date end, boolean assumeSameDate, boolean assumeSameHour)
  9. secondsToEndOfDay(Date aDate)