Java Date Before isBeforeEndOfDate(Date subject, Date predicate)

Here you can find the source of isBeforeEndOfDate(Date subject, Date predicate)

Description

Is the subject date before the end of the predicate date?

License

Open Source License

Parameter

Parameter Description
subject a parameter
predicate a parameter

Declaration

public static boolean isBeforeEndOfDate(Date subject, Date predicate) 

Method Source Code


//package com.java2s;
/*//w  w  w  .j  a  v  a2s .c o m
 * Copyright 2004 - 2008 Christian Sprajc. All rights reserved.
 *
 * This file is part of PowerFolder.
 *
 * PowerFolder is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * PowerFolder is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PowerFolder. If not, see <http://www.gnu.org/licenses/>.
 *
 * $Id: DateUtil.java 9297 2009-09-03 19:17:22Z tot $
 */

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

public class Main {
    /**
     * Is the subject date before the end of the predicate date?
     * '5 December 2009 21:15:45' is before end of '5 December 2009'.
     * Actually tests that subject is before day-after-predicate.
     *
     * @param subject
     * @param predicate
     * @return
     */
    public static boolean isBeforeEndOfDate(Date subject, Date predicate) {

        Calendar cal = new GregorianCalendar();
        cal.setTime(zeroTime(predicate));
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DATE, 1);
        return subject.before(cal.getTime());
    }

    /**
     * Returns a date that is the same day as the arg with all time parts == 0.
     *
     * @param date
     * @return
     */
    public static Date zeroTime(Date date) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
}

Related

  1. isBefore(Date date1, Date date2)
  2. isBefore2015(Date date)
  3. isBefore_day(Date time1, Date time2, int days)
  4. isBeforeCommonEra(Date date)
  5. isBeforeDate(long time1, long time2)
  6. isDataBeforeData2TruncByDay(Date data1, Date data2)
  7. isDateBeforeCurrentDate(Date date)
  8. monthInRange(Date current, Date before, Date after)