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:com.feilong.commons.core.date.DateUtil.java

/**
 * ??./*www. j a v a2s.  co  m*/
 * 
 * <pre>
 *  :2012-10-16 23:00:02
 * 
 * isInTime(date, "2012-10-10 22:59:00", "2012-10-18 22:59:00")
 * 
 * return true
 * </pre>
 * 
 * @param date
 *            ?
 * @param beginTimeDate
 *            the begin time date
 * @param endTimeDate
 *            the end time date
 * @return {@code  date after beginTimeDate&&?before endTimeDate,true}
 * @see Date#after(Date)
 * @see Date#before(Date)
 */
public static final boolean isInTime(Date date, Date beginTimeDate, Date endTimeDate) {
    boolean flag = date.after(beginTimeDate) && date.before(endTimeDate);
    return flag;
}

From source file:com.intuit.wasabi.experimentobjects.ExperimentValidator.java

protected void validateExperimentStartEnd(Date startTime, Date endTime) {
    if (startTime == null || endTime == null)
        throw new IllegalArgumentException(
                "Invalid date range, start = \"" + startTime + "\", end = " + "\"" + endTime + "\"");

    if (endTime.before(startTime)) {
        throw new IllegalArgumentException(
                "Invalid date range, start = \"" + startTime + "\", end = " + "\"" + endTime + "\"");
    }//w w  w.j av  a2s  .  c  o m
}

From source file:com.tk.httpClientErp.wsHeadCheck.WsHeadCheckList.java

@SuppressLint("SimpleDateFormat")
private boolean compareTime(String ComTime, String ToTime) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date1 = new Date();
    Date date2 = new Date();
    try {//from  www .  j a v a 2s . c  o  m
        date1 = sdf.parse(ComTime);
        date2 = sdf.parse(ToTime);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return date1.before(date2);
}

From source file:net.audumla.climate.bom.BOMPeriodicClimateObserver.java

public boolean supportsDate(Date date) {
    Date limit = DateUtils.addDays(Time.getDayAndYear(date), -2); // This observer can support observations for 3 days including today.
    return !(date.before(limit) || date.after(Time.getNow()));
}

From source file:com.abiquo.abiserver.business.authentication.AuthenticationManagerDB.java

@Override
public BasicResult checkSession(final UserSession userSession) {
    BasicResult checkSessionResult = new BasicResult();

    Session session = null;//from www. ja  va 2  s. com
    Transaction transaction = null;

    UserSession sessionToCheck = null;

    try {
        session = HibernateUtil.getSession();
        transaction = session.beginTransaction();

        sessionToCheck = (UserSession) HibernateUtil.getSession().createCriteria(UserSession.class)
                .add(Restrictions.eq("user", userSession.getUser()))
                .add(Restrictions.eq("key", userSession.getKey())).uniqueResult();

        if (sessionToCheck == null) {
            // The session does not exist, so is not valid
            checkSessionResult.setResultCode(BasicResult.SESSION_INVALID);
            logger.trace("Invalod session. Please login again");
        } else {
            // Checking if the session has expired
            Date currentDate = new Date();
            if (currentDate.before(sessionToCheck.getExpireDate())) {
                // The session is valid updating the expire Date
                int sessionTimeout = abiConfig.getSessionTimeout();
                long expireMilis = new Date().getTime() + sessionTimeout * 60 * 1000;
                Date expireDate = new Date(expireMilis);
                sessionToCheck.setExpireDate(expireDate);

                session.update(sessionToCheck);

                checkSessionResult.setSuccess(true);
                checkSessionResult
                        .setMessage(AuthenticationManagerDB.resourceManger.getMessage("checkSession.success"));
            } else {
                // The session has time out. Deleting the session from Data Base
                session.delete(sessionToCheck);

                checkSessionResult.setResultCode(BasicResult.SESSION_TIMEOUT);
                logger.trace("Session expired. Please login again");
            }

        }

        transaction.commit();
    } catch (Exception e) {
        if (transaction != null && transaction.isActive()) {
            transaction.rollback();
        }

        logger.trace("Unexpected error while checking the user session", e);
    }

    return checkSessionResult;
}

From source file:com.hs.mail.imap.schedule.MessageCompressor.java

public void compress(String prop, long timeLimit) {
    Date base = ScheduleUtils.getDateBefore(prop);
    if (base != null) {
        Date start = getStartDate(base);
        if (start != null) {
            Date date = start;
            if (logger.isDebugEnabled()) {
                logger.debug("Compressing directories from " + DateFormatUtils.ISO_DATE_FORMAT.format(start)
                        + " to " + DateFormatUtils.ISO_DATE_FORMAT.format(base));
            }/*from  www  . ja v  a 2s .  c o  m*/
            while (date.before(base) && System.currentTimeMillis() < timeLimit) {
                compressDirectories(date, timeLimit);
                date = DateUtils.addDays(date, 1);
            }
        }
    }
}

From source file:net.audumla.climate.bom.BOMSimpleHistoricalClimateObserver.java

public boolean supportsDate(Date date) {
    return !invalidMonths.contains(Time.getMonthAndYear(date))
            && (date.before(Time.getToday()) || DateUtils.isSameDay(date, Time.getToday()));
}

From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsHelper.java

private List<Entity> findCurrentAssignmentsToShiftForCrew(final Date date,
        List<Entity> assignmentsToShiftForCrew) {

    List<Entity> currentAssignments = Lists.newArrayList();
    if (assignmentsToShiftForCrew == null) {
        return currentAssignments;
    }//w w  w. j a  v  a2  s  . co  m
    Date currentDate = date;
    for (Entity assignmentToShift : assignmentsToShiftForCrew) {
        Date assignmentDate = assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE);
        if (assignmentDate.before(currentDate)) {
            if (currentAssignments.isEmpty()) {
                currentAssignments.add(assignmentToShift);
            } else {
                return currentAssignments;
            }
        } else if (assignmentDate.compareTo(currentDate) == 0) {
            currentAssignments.add(assignmentToShift);
        }
        currentDate = assignmentDate;
    }
    return currentAssignments;
}

From source file:com.qcadoo.mes.masterOrders.validators.MasterOrderValidators.java

public boolean checkIfDatesAreOk(final DataDefinition masterOrderDD, final Entity masterOrder) {
    Date startDate = masterOrder.getDateField(MasterOrderFields.START_DATE);
    Date finishDate = masterOrder.getDateField(MasterOrderFields.FINISH_DATE);

    if ((startDate != null) && (finishDate != null) && finishDate.before(startDate)) {
        masterOrder.addError(masterOrderDD.getField(OrderFields.FINISH_DATE),
                "masterOrders.masterOrder.finishDate.isBeforeStartDate");

        return false;
    }/*  w  w w .j  a v a  2s  . c  o m*/

    return true;
}

From source file:de.ep3.ftpc.model.CrawlerFile.java

/**
 * Decides whether this file is relevant for crawling or not
 * (depending on the crawler settings provided by the user).
 *
 * @param server Contains the crawler settings.
 * @param i18n To check and parse the user provided dates.
 * @return The decision./*  w w  w .  j av a  2 s .  co  m*/
 */
public boolean isRelevant(Server server, I18nManager i18n) {
    if (!isFile()) {
        return false;
    }

    if (server == null) {
        return false;
    }

    try {
        if (!server.has("crawler.file-name")) {
            return false;
        }

        if (!getName().matches(server.get("crawler.file-name"))) {
            return false;
        }
    } catch (PatternSyntaxException e) {
        return false;
    }

    long size = ftpFile.getSize() / 1024;

    if (server.has("crawler.file-size-min")) {
        long minSize = Long.parseLong(server.get("crawler.file-size-min"));

        if (size < minSize) {
            return false;
        }
    }

    if (server.has("crawler.file-size-max")) {
        long maxSize = Long.parseLong(server.get("crawler.file-size-max"));

        if (size > maxSize) {
            return false;
        }
    }

    Date date = ftpFile.getTimestamp().getTime();

    if (server.has("crawler.file-date-start")) {
        try {
            Date startDate = i18n.parseDate(server.get("crawler.file-date-start"));

            if (date.before(startDate)) {
                return false;
            }
        } catch (ParseException e) {
            return false;
        }
    }

    if (server.has("crawler.file-date-end")) {
        try {
            Date endDate = i18n.parseDate(server.get("crawler.file-date-end"));

            if (date.after(endDate)) {
                return false;
            }
        } catch (ParseException e) {
            return false;
        }
    }

    return true;
}