Java Day End checkTimePeriod(final Date beginHour, final Date endHour, final Date hour)

Here you can find the source of checkTimePeriod(final Date beginHour, final Date endHour, final Date hour)

Description

Checks time period.

License

Open Source License

Parameter

Parameter Description
beginHour a parameter
endHour a parameter
hour a parameter

Declaration

public static boolean checkTimePeriod(final Date beginHour,
        final Date endHour, final Date hour) 

Method Source Code

//package com.java2s;
/**/*from  w ww . ja v  a  2  s. com*/
 * Vulpe Framework - Quick and Smart ;)
 * Copyright (C) 2011 Active Thread
 *
 * Este programa ? software livre; voc? pode redistribu?-lo e/ou
 * modific?-lo sob os termos da Licen?a P?blica Geral GNU, conforme
 * publicada pela Free Software Foundation; tanto a vers?o 2 da
 * Licen?a como (a seu crit?rio) qualquer vers?o mais nova.
 *
 * Este programa ? distribu?do na expectativa de ser ?til, mas SEM
 * QUALQUER GARANTIA; sem mesmo a garantia impl?cita de
 * COMERCIALIZA??O ou de ADEQUA??O A QUALQUER PROP?SITO EM
 * PARTICULAR. Consulte a Licen?a P?blica Geral GNU para obter mais
 * detalhes.
 *
 * Voc? deve ter recebido uma c?pia da Licen?a P?blica Geral GNU
 * junto com este programa; se n?o, escreva para a Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     * Checks time period.
     *
     * @param beginHour
     * @param endHour
     * @param hour
     * @return
     */
    public static boolean checkTimePeriod(final Date beginHour,
            final Date endHour, final Date hour) {
        final Calendar calendarBegin = Calendar.getInstance();
        calendarBegin.setTime(beginHour);
        final Calendar calendarEnd = Calendar.getInstance();
        calendarEnd.setTime(endHour);
        final Calendar calendarTime = Calendar.getInstance();
        calendarTime.setTime(hour);

        boolean betweenPeriod = false;

        calendarBegin.set(Calendar.DAY_OF_MONTH, 1);
        calendarBegin.set(Calendar.MONTH, 1);
        calendarBegin.set(Calendar.YEAR, 1970);

        calendarEnd.set(Calendar.DAY_OF_MONTH, 2);
        calendarEnd.set(Calendar.MONTH, 1);
        calendarEnd.set(Calendar.YEAR, 1970);

        calendarTime.set(Calendar.DAY_OF_MONTH, 1);
        calendarTime.set(Calendar.MONTH, 1);
        calendarTime.set(Calendar.YEAR, 1970);

        if (calendarTime.after(calendarBegin)
                && calendarTime.before(calendarEnd)) {
            betweenPeriod = true;
        } else {
            calendarTime.set(Calendar.DAY_OF_MONTH, 2);
            if (calendarTime.after(calendarBegin)
                    && calendarTime.before(calendarEnd)) {
                betweenPeriod = true;
            }
        }
        return betweenPeriod;
    }
}

Related

  1. absoluteDay(Calendar cal)
  2. calculateMaxStartDate(Calendar calendar, int daysAhead)
  3. calcYears(Date startDate, Date endDate)
  4. calenderFromDateString(String dateAndTime)
  5. checkTimeInRangeWithSkew(Date timeToCheck, Date startDate, Date endDate, int skewInMinutes)
  6. countDaysBetween(Date start, Date end)
  7. countMonths(java.util.Date startDate, java.util.Date endDate)
  8. dateBetweens(Date start, Date end)
  9. dateSpan(Date beginDate, Date endDate)