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:net.kamhon.ieagle.util.DateUtil.java

/**
 * Return those date in dates which is between fromDate and toDate.
 * /* w  w w.j  a  va2s . c o  m*/
 * @return
 */
public static List<Date> getDateBetween(List<Date> dates, Date fromDate, Date toDate) {
    List<Date> retDateList = new ArrayList<Date>();

    for (Date date : dates) {
        if (fromDate.equals(date) || toDate.equals(date) || date.after(fromDate) && date.before(toDate)) {
            retDateList.add(date);
        }
    }

    if (retDateList.size() > 1) {
        Collections.sort(retDateList);
    }
    return retDateList;
}

From source file:Main.java

/**
 * The snapped start how long/*from  w w w .j  a  va 2 s.  c o m*/
 * 
 * @param startTime
 * @param currentTime
 * @return
 */
public static boolean isStart(String startTime, String currentTime) {
    Date current = null;
    Date start = null;
    try {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        current = format.parse(currentTime);
        start = format.parse(startTime);
    } catch (ParseException e) {
        return false;
    }

    if (current != null && start != null) {
        return current.after(start);
    }

    return false;
}

From source file:org.hsweb.web.service.impl.quartz.QuartzJobServiceImpl.java

public static List<Date> computeFireTimesBetween(OperableTrigger trigger, org.quartz.Calendar cal, Date from,
        Date to, int num) {
    LinkedList<Date> lst = new LinkedList<>();
    OperableTrigger t = (OperableTrigger) trigger.clone();
    if (t.getNextFireTime() == null) {
        t.setStartTime(from);//from   w w w  .  j a va  2 s. c  o  m
        t.setEndTime(to);
        t.computeFirstFireTime(cal);
    }
    for (int i = 0; i < num; i++) {
        Date d = t.getNextFireTime();
        if (d != null) {
            if (d.before(from)) {
                t.triggered(cal);
                continue;
            }
            if (d.after(to)) {
                break;
            }
            lst.add(d);
            t.triggered(cal);
        } else {
            break;
        }
    }
    return java.util.Collections.unmodifiableList(lst);
}

From source file:org.wso2.carbon.apimgt.authenticator.oidc.util.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;//www. j a v a2 s .c o 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() - (OIDCAuthenticatorBEConstants.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() + (OIDCAuthenticatorBEConstants.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() + (OIDCAuthenticatorBEConstants.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;
}

From source file:DateUtils.java

/** 
 * Returns the maximum of two dates. A null date is treated as being less
 * than any non-null date. //from w ww  .ja  va2s  . co m
 */
public static Date max(Date d1, Date d2) {
    if (d1 == null && d2 == null)
        return null;
    if (d1 == null)
        return d2;
    if (d2 == null)
        return d1;
    return (d1.after(d2)) ? d1 : d2;
}

From source file:Main.java

/**
 * The end of the rush to buy whether// w  w  w. j  a  v a 2s. co  m
 * 
 * @param endTime
 * @param currentTime
 * @return Has been completed
 */
public static boolean isOver(String endTime, String currentTime) {
    Date current = null;
    Date end = null;
    try {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        current = format.parse(currentTime);
        end = format.parse(endTime);
    } catch (IllegalArgumentException e) {
        return false;
    } catch (ParseException e) {
        return false;
    }
    if (current != null && end != null) {
        return current.after(end);
    }
    return false;
}

From source file:de.knurt.fam.template.util.ContactDetailsRequestHandler.java

public static Date correctBirthdate(Date birthdate) {
    Calendar now = Calendar.getInstance();
    // older then 0?
    if (birthdate != null) {
        if (birthdate.after(now.getTime())) {
            birthdate = null;// w  ww  .  jav a 2  s .  c  o m
        }
    }
    if (birthdate != null) {
        // younger then 200?
        now.roll(Calendar.YEAR, -200);
        if (birthdate.before(now.getTime())) {
            birthdate = null;
        }
    }
    return birthdate;
}

From source file:net.larry1123.elec.util.logger.FileManager.java

public static long getSplitTime() {
    long set = System.currentTimeMillis();
    try {/*from w w w  .  ja v  a2 s  .c  o m*/
        Date currentTime = DateUtils.parseDate(getDateFormatFromMilli(System.currentTimeMillis()),
                DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern());
        Date currentSplit = DateUtils.parseDate(getDateFormatFromMilli(getConfig().getCurrentSplit()),
                DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern());
        Date test;
        switch (getConfig().getSplit()) {
        case HOUR:
            test = DateUtils.addHours(currentTime, 1);
            test = DateUtils.setMinutes(test, 0);
            test = DateUtils.setSeconds(test, 0);
            test = DateUtils.setMilliseconds(test, 0);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case DAY:
            if (!DateUtils.isSameDay(currentTime, currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case WEEK:
            test = DateUtils.ceiling(currentTime, Calendar.WEEK_OF_MONTH);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case MONTH:
            test = DateUtils.ceiling(currentTime, Calendar.MONTH);
            if (test.after(currentSplit)) {
                set = getConfig().getCurrentSplit();
            }
            break;
        case NONE:
        default:
            set = 0;
            break;
        }
    } catch (ParseException e) {
        set = 0;
    }
    return set;
}

From source file:de.micromata.genome.gwiki.controls.GWikiPageImporterActionBean.java

public static CompareStatus getCompareStatus(GWikiContext wikiContext, GWikiElementInfo ei, String oldPageId) {
    GWikiElementInfo oei = wikiContext.getWikiWeb().getStorage().loadElementInfo(oldPageId);
    if (oei == null) {
        return CompareStatus.NEW;
    }/*from w ww .ja v  a  2  s .  c  o m*/
    Date nd = ei.getModifiedAt();
    Date od = oei.getModifiedAt();
    if (od == null || nd == null) {
        return CompareStatus.EXISTS;
    }
    if (nd.after(od) == true) {
        return CompareStatus.NEWER;
    } else if (nd.before(od) == true) {
        return CompareStatus.OLDER;
    }
    return CompareStatus.EQUAL;
}

From source file:com.projity.server.data.mspdi.ModifiedMSPDIReader.java

private static boolean CombineTimephasedDataIfOnSameDay(TimephasedDataType original,
        TimephasedDataType newData) {/*from ww  w  . j  a  va  2s  .c  o m*/
    boolean dataCombined = false;
    Date newStart = newData.getStart().getTime();
    Date newFinish = newData.getFinish().getTime();
    Date originalStart = original.getStart().getTime();
    Date originalFinish = original.getFinish().getTime();
    if (newStart.after(originalStart) && newFinish.before(originalFinish)) {
        long sumValue = XsdDuration.millis(original.getValue()) + XsdDuration.millis(newData.getValue());
        Duration combined = Duration.getInstance(sumValue / WorkCalendar.MILLIS_IN_MINUTE, TimeUnit.MINUTES);
        original.setValue(new XsdDuration(combined).toString());
        dataCombined = true;
    }

    return dataCombined;
}