Example usage for java.util Date after

List of usage examples for java.util Date after

Introduction

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

Prototype

public boolean after(Date when) 

Source Link

Document

Tests if this date is after the specified date.

Usage

From source file:com.projity.util.DateTime.java

public static Date max(Date date1, Date date2) {
    return date1.after(date2) ? date1 : date2;
}

From source file:com.inkubator.common.util.DateTimeUtil.java

/**
 * get total SaturDay and Monday between two date
 *
 * @param startDate Date reference//from w w  w .  j av  a2s. co  m
 * @return Integer
 * @param endDate Date reference
 * @throws java.lang.Exception
 */
public static Integer getTotalSaturdayAndMonday(Date startDate, Date endDate) throws Exception {
    if (startDate.after(endDate)) {
        throw new Exception("Mr. DHFR say :End Date must be newer than Start Date");
    } else {
        DateTime start = new DateTime(startDate);
        DateTime end = new DateTime(endDate);
        int totalSaturdayAndMonday = 0;
        DateTime iterate = start;
        while (iterate.isBefore(end) | iterate.isEqual(end)) {
            if (iterate.getDayOfWeek() == 6 | iterate.getDayOfWeek() == 7) {
                ++totalSaturdayAndMonday;
            }
            iterate = iterate.plusDays(1);
        }
        return totalSaturdayAndMonday;
    }
}

From source file:mitm.common.security.crl.X509CRLInspector.java

/**
 * Returns true if nextUpdate is before the current date
 *///  w  w w.j ava2 s  .c  o  m
public static boolean isExpired(X509CRL crl) {
    boolean expired = false;

    Date now = new Date();

    expired = crl.getNextUpdate() != null && now.after(crl.getNextUpdate());

    return expired;
}

From source file:gov.nasa.arc.spife.ui.table.days.Day.java

public static boolean intersectsExtent(TemporalExtent dayExtent, Date elementStart, Date elementEnd) {
    Date dayStart = dayExtent.getStart();
    if (elementEnd.before(dayStart)) {
        return false;
    }// w ww . j  a  v  a 2s .co  m
    Date dayEnd = dayExtent.getEnd();
    if (elementStart.after(dayEnd)) {
        return false;
    }
    if (elementEnd.equals(dayStart) && !elementStart.equals(dayStart)) {
        return false;
    }
    return true;
}

From source file:io.github.seiferma.jameica.hibiscus.dkb.creditcard.synchronize.DKBScraperSynchronizeJobKontoauszugImpl.java

private static Date getLatestDate(Iterable<Umsatz> transactions) throws RemoteException {
    Date latestDate = null;
    for (Umsatz transaction : transactions) {
        Date transactionDate = transaction.getDatum();
        if (latestDate == null || latestDate.after(transactionDate)) {
            latestDate = transactionDate;
        }//from   www .ja va2  s  . c  om
    }
    return latestDate;
}

From source file:com.redhat.rhn.testing.RhnBaseTestCase.java

/**
 * Assert that the date <code>later</code> is after the date
 * <code>earlier</code>. The assertion succeeds if the dates
 * are equal. Both dates must be non-null.
 *
 * @param msg the message to print if the assertion fails
 * @param earlier the earlier date to compare
 * @param later the later date to compare
 *//* w w  w. j a v a  2  s  .  c om*/
public static void assertNotBefore(String msg, Date earlier, Date later) {
    assertNotNull(msg, earlier);
    assertNotNull(msg, later);
    if (earlier.after(later) && !earlier.equals(later)) {
        String e = DateFormat.getDateTimeInstance().format(earlier);
        String l = DateFormat.getDateTimeInstance().format(later);
        throw new ComparisonFailure(msg, e, l);
    }
}

From source file:com.dajodi.scandic.Util.java

public static int daysBetween(Date before, Date after) {

    if (before == null || after == null) {
        return UNKNOWN_NIGHTS;
    }//from ww  w.j  a v a 2 s  . c o  m

    if (before.after(after)) {
        return UNKNOWN_NIGHTS;
    }

    // Creates two calendars instances
    Calendar cal1 = Calendar.getInstance();
    cal1.setTime(before);
    int day1 = cal1.get(Calendar.DAY_OF_YEAR);

    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(after);
    int day2 = cal2.get(Calendar.DAY_OF_YEAR);

    long diffDays = UNKNOWN_NIGHTS;
    if (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)) {
        diffDays = Math.abs(day2 - day1);
    }

    // Calculate difference in days
    return (int) diffDays;
}

From source file:net.kamhon.ieagle.util.DateUtil.java

/**
 * consider time and date.//from w  w  w .  ja  va  2  s.  c o m
 * 
 * @param date
 * @param startDate
 * @param endDate
 * @return
 */
public static boolean isBetweenDateTime(Date date, Date startDate, Date endDate) {
    return (date.equals(startDate) || date.after(startDate)) && (date.equals(endDate) || date.before(endDate));
}

From source file:com.inkubator.common.util.DateTimeUtil.java

/**
 * get total working days//  w  w  w.j av  a2s.  c  om
 *
 * @param startDate Date reference
 * @return Integer
 * @param endDate Date reference
 * @param totalPublicHoliday total of public holiday in target country
 * @param totalAnnualLeave total of annual leave
 * @throws java.lang.Exception
 */
public static Integer getTotalWorkingDay(Date startDate, Date endDate, int totalPublicHoliday,
        int totalAnnualLeave) throws Exception {
    if (startDate.after(endDate)) {
        throw new Exception(" Mr. DHFR say :End Date must be newer than Start Date");
    } else {
        int workingDays = getTotalDay(startDate, endDate) - getTotalSaturdayAndMonday(startDate, endDate);
        Integer totalWorkingDay = workingDays - totalAnnualLeave - totalPublicHoliday;
        return totalWorkingDay;
    }
}

From source file:org.wso2.carbon.apimgt.hostobjects.oidc.internal.Util.java

public static boolean validateIdClaims(ServerConfiguration serverConfiguration, AuthClient authClient,
        JWT idToken, String nonce, ReadOnlyJWTClaimsSet idClaims) throws Exception {

    boolean isValid = true;
    String clientId = authClient.getClientId();
    String clientAlgorithm = authClient.getClientAlgorithm();
    Algorithm tokenAlg = idToken.getHeader().getAlgorithm();

    if (clientAlgorithm != null) {

        Algorithm clientAlg = new Algorithm(clientAlgorithm);
        if (!clientAlg.equals(tokenAlg)) {
            isValid = false;/*from ww w  .  j  ava 2  s .  co m*/
            log.error("Token algorithm " + tokenAlg + " does not match expected algorithm " + clientAlg);
        }
    }

    // check the issuer
    if (idClaims.getIssuer() == null) {
        isValid = false;
        log.error("Id Token Issuer is null");
    } else if (!idClaims.getIssuer().equals(serverConfiguration.getIssuer())) {
        isValid = false;
        log.error("Issuers do not match, expected " + serverConfiguration.getIssuer() + " got "
                + idClaims.getIssuer());
    }

    // check expiration
    if (idClaims.getExpirationTime() == null) {
        isValid = false;
        log.error("Id Token does not have required expiration claim");
    } else {
        // it's not null, see if it's expired
        Date now = new Date(System.currentTimeMillis() - (OIDCConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.after(idClaims.getExpirationTime())) {
            isValid = false;
            log.error("Id Token is expired: " + idClaims.getExpirationTime());
        }
    }

    // check not before
    if (idClaims.getNotBeforeTime() != null) {
        Date now = new Date(System.currentTimeMillis() + (OIDCConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.before(idClaims.getNotBeforeTime())) {
            isValid = false;
            log.error("Id Token not valid untill: " + idClaims.getNotBeforeTime());
        }
    }

    // check issued at
    if (idClaims.getIssueTime() == null) {
        isValid = false;
        log.error("Id Token does not have required issued-at claim");
    } else {
        // since it's not null, see if it was issued in the future
        Date now = new Date(System.currentTimeMillis() + (OIDCConstants.TIME_SKEW_ALLOWANCE * 1000));
        if (now.before(idClaims.getIssueTime())) {
            isValid = false;
            log.error("Id Token was issued in the future: " + idClaims.getIssueTime());
        }
    }

    // check audience
    if (idClaims.getAudience() == null) {
        isValid = false;
        log.error("Id token audience is null");
    } else if (!idClaims.getAudience().contains(clientId)) {
        isValid = false;
        log.error("Audience does not match, expected " + clientId + " got " + idClaims.getAudience());
    }

    // compare the nonce to our stored claim
    String nonceValue = idClaims.getStringClaim("nonce");
    if (nonceValue == null || "".equals(nonceValue)) {
        isValid = false;
        log.error("ID token did not contain a nonce claim.");
    } else if (!nonceValue.equals(nonce)) {
        isValid = false;
        log.error("Possible replay attack detected! The comparison of the nonce in the returned "
                + "ID Token to the session " + "NONCE" + " failed. Expected " + nonce + " got " + nonceValue
                + ".");

    }

    return isValid;
}