Java Calendar Day isAfterDay(Calendar cal1, Calendar cal2)

Here you can find the source of isAfterDay(Calendar cal1, Calendar cal2)

Description

Checks if the first calendar date is after the second calendar date ignoring time.

License

Open Source License

Parameter

Parameter Description
cal1 the first calendar, not altered, not null.
cal2 the second calendar, not altered, not null.

Exception

Parameter Description
IllegalArgumentException if either of the calendars are<code>null</code>

Return

true if cal1 date is after cal2 date ignoring time.

Declaration

public static boolean isAfterDay(Calendar cal1, Calendar cal2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*w w  w . ja  v  a2 s . c o m*/
     * <p>
     * Checks if the first date is after the second date ignoring time.
     * </p>
     * 
     * @param date1 the first date, not altered, not null
     * @param date2 the second date, not altered, not null
     * @return true if the first date day is after the second date day.
     * @throws IllegalArgumentException if the date is <code>null</code>
     */
    public static boolean isAfterDay(Date date1, Date date2) {
        if (date1 == null || date2 == null) {
            throw new IllegalArgumentException("The dates must not be null");
        }
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);
        return isAfterDay(cal1, cal2);
    }

    /**
     * <p>
     * Checks if the first calendar date is after the second calendar date
     * ignoring time.
     * </p>
     * 
     * @param cal1 the first calendar, not altered, not null.
     * @param cal2 the second calendar, not altered, not null.
     * @return true if cal1 date is after cal2 date ignoring time.
     * @throws IllegalArgumentException if either of the calendars are
     *             <code>null</code>
     */
    public static boolean isAfterDay(Calendar cal1, Calendar cal2) {
        if (cal1 == null || cal2 == null) {
            throw new IllegalArgumentException("The dates must not be null");
        }
        if (cal1.get(Calendar.ERA) < cal2.get(Calendar.ERA))
            return false;
        if (cal1.get(Calendar.ERA) > cal2.get(Calendar.ERA))
            return true;
        if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR))
            return false;
        if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR))
            return true;
        return cal1.get(Calendar.DAY_OF_YEAR) > cal2.get(Calendar.DAY_OF_YEAR);
    }
}

Related

  1. getTodayCalendar()
  2. getWorkingDay(Calendar beginDate, Calendar endDate)
  3. getWorkingDay(Calendar d1, Calendar d2)
  4. incrementDay(Calendar cal)
  5. incrementOneDay(Calendar calendar)
  6. isAllDayEvent(Calendar dtStart, Calendar dtEnd)
  7. isBusinessDay(Calendar cal)
  8. isDayAfter(Calendar calendar, Calendar baseCalendar)
  9. isDSTChangeDay(Calendar cal)