Checks if the given argument is before or on a given date. - Java java.lang

Java examples for java.lang:Assert

Description

Checks if the given argument is before or on a given date.

Demo Code


//package com.java2s;

import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        Date value = new Date();
        Date beforeOrOn = new Date();
        System.out.println(isBeforeOrOn(value, beforeOrOn));
    }// ww w  . jav a  2s  . c  om

    /**
     * Checks if the given argument is before or on a given date.
     * @param value The value of the argument to check.
     * @param beforeorEqual The date which must be preceded by value or value
     *        must be on this date.
     * @return True when value precedes or is on the given beforeOrEqual date;
     *         false otherwise.
     */
    public static boolean isBeforeOrOn(Date value, Date beforeOrOn) {
        return (value == null) || (beforeOrOn == null)
                || !(value.before(beforeOrOn) || value.equals(beforeOrOn));
    }
}

Related Tutorials