Java Calendar Calculate isInWorkTime(Calendar start)

Here you can find the source of isInWorkTime(Calendar start)

Description

Determines whether or not the time of the date is within the work day

License

Apache License

Declaration

public static boolean isInWorkTime(Calendar start) 

Method Source Code

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

import java.util.*;

public class Main {
    /**/* ww  w.  ja va 2  s.  co m*/
     * The default when the workday ends (5PM)
     */
    public static final int END_WORKDAY = 17;
    /**
     * The default when the workday starts (7AM)
     */
    public static final int START_WORKDAY = 7;

    /**
     * Determines whether or not the time of the date is within the work day
     *
     * @see #START_WORKDAY
     * @see #END_WORKDAY
     * @see #isBeforeWorkTime(Calendar)
     * @see #isAfterWorkTime(Calendar)
     */
    public static boolean isInWorkTime(Calendar start) {
        return !isBeforeWorkTime(start) && !isAfterWorkTime(start);
    }

    /**
     * Determines whether or not the date is before the start of the work day
     *
     * @see #START_WORKDAY
     */
    public static boolean isBeforeWorkTime(Calendar start) {
        final int hourOfDay = start.get(Calendar.HOUR_OF_DAY);
        return hourOfDay < START_WORKDAY;
    }

    /**
     * Determines whether or not the date is after the start of the work day
     *
     * @see #END_WORKDAY
     */
    public static boolean isAfterWorkTime(Calendar start) {
        final int hourOfDay = start.get(Calendar.HOUR_OF_DAY);
        return hourOfDay >= END_WORKDAY;
    }
}

Related

  1. getLongTime(Calendar cal)
  2. getTimeStr3(Calendar timeInstance)
  3. getTimeString(Calendar cal)
  4. getTimeStrWithMillisecond(Calendar timeInstance)
  5. isAfterWorkTime(Calendar start)
  6. isSameInstant(Calendar cal1, Calendar cal2)
  7. isSameLocalTime(Calendar cal1, Calendar cal2)
  8. maximizeTime(Calendar cal)
  9. millisToCalendar(long millis)