Example usage for java.util Date before

List of usage examples for java.util Date before

Introduction

In this page you can find the example usage for java.util Date before.

Prototype

public boolean before(Date when) 

Source Link

Document

Tests if this date is before the specified date.

Usage

From source file:Main.java

public static boolean between(Date beginDate, Date endDate, Date src) {
    return beginDate.before(src) && endDate.after(src);
}

From source file:Main.java

public static boolean isWithinRange(Date toCheck, Date start, Date end) {
    return !(toCheck.before(start) || toCheck.after(end));
}

From source file:Main.java

public static boolean inBetweenDate(Calendar first, Calendar last) {

    Date min = first.getTime();/*from w w w.  j av a  2 s  . c  o m*/
    Date max = last.getTime();

    boolean check = max.before(min);
    boolean check2 = max.equals(min);

    return !(check || check2);
}

From source file:Main.java

public static boolean isToDay(Date date) {
    DateFormat dateFormat = DateFormat.getDateInstance();
    String format = dateFormat.format(new Date());
    try {//w ww  .  j av a  2 s  .com
        Date today = dateFormat.parse(format);
        return today.before(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:Main.java

/**
 * Tests if the given base date is strictly between the given start date and
 * end date./*  w  w w .  j a v  a2  s.c om*/
 *
 * @param baseDate  the date used as base for the test.
 * @param startDate the start date.
 * @param endDate   the end date.
 * @return <code>true</code> if the base date is between the start date
 * and end date, <code>false</code> otherwise.
 */
public static boolean strictlyBetween(Date baseDate, Date startDate, Date endDate) {
    if (startDate.equals(endDate) || endDate.before(startDate)) {
        return false;
    }

    if (startDate.before(baseDate) && endDate.after(baseDate)) {
        return true;
    }

    return false;
}

From source file:Main.java

/**
 * Tests if the given base date is between the given start date and end
 * date, including the dates themselves.
 *
 * @param baseDate  the date used as base for the test.
 * @param startDate the start date.//  ww  w . java 2  s.  c o m
 * @param endDate   the end date.
 * @return <code>true</code> if the base date is between the start date
 * and end date, <code>false</code> otherwise.
 */
public static boolean between(Date baseDate, Date startDate, Date endDate) {
    if (startDate.equals(endDate) || endDate.before(startDate)) {
        return false;
    }

    if ((startDate.before(baseDate) || startDate.equals(baseDate))
            && (endDate.after(baseDate) || endDate.equals(baseDate))) {
        return true;
    }

    return false;
}

From source file:ch.newscron.newscronjsp.ReferralSignUpServlet.java

private static boolean isDateValid(String dateValidity) {
    try {//from   ww  w . java 2s . c  o  m
        //datevalidity format assumption: dd.mm.yy
        Date referralDate = new SimpleDateFormat("dd.MM.yy").parse(dateValidity);
        Date today = new Date();
        if (today.before(referralDate)) {
            return true;
        }
    } catch (ParseException ex) {
        Logger.getLogger(ReferralSignUpServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
}

From source file:com.adaptris.core.event.LicenseExpiryWarningEvent.java

private static Date min(Date d1, Date d2) {
    return (d1.before(d2)) ? d1 : d2;
}

From source file:Main.java

public static String formatExpirationDate(String text) {

    try {//from w w  w . j a v a  2 s  .c om
        switch (text.length()) {
        case 1:
            int digit = Integer.parseInt(text);

            if (digit < 2) {
                return text;
            } else {
                return "0" + text + "/";
            }
        case 2:
            int month = Integer.parseInt(text);
            if (month > 12 || month < 1) {
                // Invalid digit
                return text.substring(0, 1);
            } else {
                return text + "/";
            }
        case 3:
            if (text.substring(2, 3).equalsIgnoreCase("/")) {
                return text;
            } else {
                text = text.substring(0, 2) + "/" + text.substring(2, 3);
            }
        case 4:
            int yearDigit = Integer.parseInt(text.substring(3, 4));
            String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
            int currentYearDigit = Integer.parseInt(year.substring(2, 3));
            if (yearDigit < currentYearDigit) {
                // Less than current year invalid
                return text.substring(0, 3);
            } else {
                return text;
            }
        case 5:
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/yy");
            simpleDateFormat.setLenient(false);
            Date expiry = simpleDateFormat.parse(text);
            if (expiry.before(new Date())) {
                // Invalid exp date
                return text.substring(0, 4);
            } else {
                return text;
            }
        default:
            if (text.length() > 5) {
                return text.substring(0, 5);
            } else {
                return text;
            }
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // If an exception is thrown we clear out the text
    return "";
}

From source file:Main.java

public static String formatExpirationDate(String text) {
    try {/*from  w  w  w.ja  v a  2s  .c  o m*/
        switch (text.length()) {
        case 1:
            int digit = Integer.parseInt(text);

            if (digit < 2) {
                return text;
            } else {
                return "0" + text + "/";
            }
        case 2:
            int month = Integer.parseInt(text);
            if (month > 12 || month < 1) {
                // Invalid digit
                return text.substring(0, 1);
            } else {
                return text + "/";
            }
        case 3:
            if (text.substring(2, 3).equalsIgnoreCase("/")) {
                return text;
            } else {
                text = text.substring(0, 2) + "/" + text.substring(2, 3);
            }
        case 4:
            Calendar now = getCurrentExpDate();
            String currentYearStr = String.valueOf(now.get(Calendar.YEAR));

            int yearDigit = Integer.parseInt(text.substring(3, 4));
            int currentYearDigit = Integer.parseInt(currentYearStr.substring(2, 3));
            if (yearDigit < currentYearDigit) {
                // Less than current year invalid
                return text.substring(0, 3);
            } else {
                return text;
            }
        case 5:
            // always make the year in the current century
            Calendar now2 = getCurrentExpDate();
            String currentYearStr2 = String.valueOf(now2.get(Calendar.YEAR));
            String yearStr = text.substring(0, 3) + currentYearStr2.substring(0, 2) + text.substring(3, 5);
            Date expiry = simpleDateFormat.parse(yearStr);
            if (expiry.before(now2.getTime())) {
                // Invalid exp date
                return text.substring(0, 4);
            } else {
                return text;
            }
        default:
            if (text.length() > 5) {
                return text.substring(0, 5);
            } else {
                return text;
            }
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // If an exception is thrown we clear out the text
    return "";
}