Java Calendar Year isBeforeDay(Calendar date1, Calendar date2, boolean ignoreYear)

Here you can find the source of isBeforeDay(Calendar date1, Calendar date2, boolean ignoreYear)

Description

Returns true if the first date is before the second comparing day, month, and year.

License

Open Source License

Parameter

Parameter Description
date1 a parameter
date2 a parameter
ignoreYear a parameter

Declaration

public static boolean isBeforeDay(Calendar date1, Calendar date2, boolean ignoreYear) 

Method Source Code

//package com.java2s;
/*//from  w w  w .  j  a v a  2s  . co  m
 * Wiki_in_a_jar
 * 
 * Copyright (C) 2007 rico_g AT users DOT sourceforge DOT net
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License s published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program 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
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * 
 */

import java.util.Calendar;

public class Main {
    /**
     * Returns <code>true</code> if the first date is before the second
     * comparing day, month, and year.
     * 
     * @param date1
     * @param date2
     * @param ignoreYear
     * @return
     */
    public static boolean isBeforeDay(Calendar date1, Calendar date2, boolean ignoreYear) {
        int year1 = date1.get(Calendar.YEAR);
        int year2 = date2.get(Calendar.YEAR);
        int month1 = date1.get(Calendar.MONTH);
        int month2 = date2.get(Calendar.MONTH);
        int day1 = date1.get(Calendar.DAY_OF_MONTH);
        int day2 = date2.get(Calendar.DAY_OF_MONTH);

        if (!ignoreYear && year1 < year2) {
            return true;
        }
        if (!ignoreYear && year1 > year2) {
            return false;
        }
        // same year:
        if (month1 < month2) {
            return true;
        }
        if (month1 > month2) {
            return false;
        }
        // same month
        return day1 < day2;
    }
}

Related

  1. getYear(Calendar calendar)
  2. getYear(Calendar calendar)
  3. getYear(Date date, Calendar cal)
  4. getYearForWeek(final Calendar cal)
  5. getYearList(Calendar currDate)
  6. isSameDay(Calendar date1, Calendar date2, boolean ignoreYear)
  7. isSameDayOfYear(Calendar calendar1, Calendar calendar2)
  8. isSameWeekOfYear(Calendar calendar1, Calendar calendar2)
  9. isToThisDayOrLater(int year, int month, int day, java.util.Calendar start, java.util.Calendar end)