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:gov.nasa.ensemble.common.io.FileUtilities.java

/**
 * recursive last modified method//w ww.j  ava2 s  .  c o  m
 * 
 * @param file
 * @return Date
 */
public static Date getLastModified(File file) {
    Date date = null;
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        for (File currentFile : files) {
            Date currentLastModifiedDate = getLastModified(currentFile);
            if (date == null || (currentLastModifiedDate != null && date.before(currentLastModifiedDate))) {
                date = currentLastModifiedDate;
            }
        }
    } else {
        date = new Date(file.lastModified());
    }
    return date;
}

From source file:agileinterop.AgileInterop.java

private static JSONObject getPSRList(String body)
        throws ParseException, InterruptedException, java.text.ParseException, Exception {
    // Parse body as JSON
    JSONParser parser = new JSONParser();
    JSONObject jsonBody = (JSONObject) parser.parse(body);

    Date startDateOriginated = new SimpleDateFormat("MM/dd/yyyy")
            .parse(jsonBody.get("startDateOriginated").toString());
    Date endDateOriginated = new SimpleDateFormat("MM/dd/yyyy")
            .parse(jsonBody.get("endDateOriginated").toString());

    List<String> data = new ArrayList<>();

    class getPSRListForDate implements Runnable {
        private Date dateOriginated;
        private List<String> data;

        public getPSRListForDate(Date dateOriginated, List<String> data) {
            this.dateOriginated = dateOriginated;
            this.data = data;
        }//from  w w w .ja v a 2s.co m

        public getPSRListForDate(List<String> data) {
            this.data = data;
        }

        @Override
        public void run() {
            try {
                String dateOriginatedString = new SimpleDateFormat("MM/dd/yyyy").format(dateOriginated);

                Long startTime = System.currentTimeMillis();

                IQuery query = (IQuery) Agile.session.createObject(IQuery.OBJECT_TYPE,
                        "Product Service Requests");

                String criteria = "[Cover Page.Date Originated] == '" + dateOriginatedString
                        + " 12:00:00 AM GMT' AND "
                        + "[Cover Page.Type] IN ('Customer Complaint', 'Customer Inquiry', 'Partner Complaint', "
                        + "'Reportable Malfunction / Adverse Event', 'Ancillary Devices & Applications', 'Distributors / Partners', "
                        + "'MDR Decision Tree', 'Investigation Report - No RGA', 'Investigation Report - RGA')";
                query.setCriteria(criteria);

                query.setResultAttributes(new Integer[] { 4856 }); // 4856 = Object ID of [Cover Page.PSR Number]

                ITable queryResults = query.execute();
                queryResults.setPageSize(5000);

                ITwoWayIterator tableIterator = queryResults.getTableIterator();
                while (tableIterator.hasNext()) {
                    IRow row = (IRow) tableIterator.next();
                    data.add(row.getCell(4856).toString()); // 4856 = Object ID of [Cover Page.PSR Number]
                }

                Long endTime = System.currentTimeMillis();

                String logMessage = String.format("getPSRList: Query for %s executed in %d milliseconds",
                        new SimpleDateFormat("yyyy-MM-dd").format(dateOriginated), endTime - startTime);
                System.out.println(logMessage);
            } catch (APIException ex) {
                Logger.getLogger(AgileInterop.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    if (startDateOriginated.after(endDateOriginated)) {
        throw new Exception("startDateOriginated is after endDateOriginated. This makes no sense, silly.");
    }

    synchronized (data) {
        Date currentDateOriginated = startDateOriginated;

        ExecutorService executor = Executors.newFixedThreadPool(6);
        do {
            executor.execute(new Thread(new getPSRListForDate(currentDateOriginated, data)));

            Calendar c = Calendar.getInstance();
            c.setTime(currentDateOriginated);
            c.add(Calendar.DATE, 1);

            currentDateOriginated = c.getTime();
        } while (currentDateOriginated.before(endDateOriginated)
                | currentDateOriginated.equals(endDateOriginated));

        executor.shutdown();
        while (!executor.isTerminated()) {
        }
    }

    JSONObject obj = new JSONObject();
    obj.put("data", data);
    return obj;
}

From source file:com.example.app.profile.ui.user.ProfileMembershipManagement.java

private static boolean isOverlapped(List<Membership> list) {
    for (Membership m1 : list) {
        final Date startA = m1.getStartDate();
        final Date endA = m1.getEndDate();

        for (Membership m2 : list) {
            if (m1 == m2)
                continue;
            final Date startB = m2.getStartDate();
            final Date endB = m2.getEndDate();
            if ((startA == null || endB == null || startA.before(endB) || startA.equals(endB))
                    && (endA == null || startB == null || endA.after(startB) || endA.equals(startB)))
                return true;
        }//from  w  ww.j a  va 2s  .c o m
    }
    return false;
}

From source file:controllers.DatasetController.java

public static Result getSearchResult() {
    Form<DataSet> dc = dataSetForm.bindFromRequest();
    ObjectNode jsonData = Json.newObject();
    String dataSetName = "";
    String agency = "";
    String instrument = "";
    String physicalVariable = "";
    String gridDimension = "";
    String startTime = "";
    String endTime = "";
    Date dataSetStartTime = new Date(0), dataSetEndTime = new Date();

    try {// www.j  a  v  a  2s . c  o m
        dataSetName = dc.field("Dataset Name").value();
        agency = dc.field("Agency").value();
        instrument = dc.field("Instrument").value();
        physicalVariable = dc.field("Physical Variable").value();
        gridDimension = dc.field("Grid Dimension").value();
        startTime = dc.field("Dataset Start Time").value();
        endTime = dc.field("Dataset End Time").value();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");

        if (!startTime.isEmpty()) {
            try {
                dataSetStartTime = simpleDateFormat.parse(startTime);
                Date min = new Date(0);
                Date max = new Date();
                if (dataSetStartTime.before(min)) {
                    dataSetStartTime = min;
                } else if (dataSetStartTime.after(max)) {
                    dataSetStartTime = max;
                }
            } catch (ParseException e) {
                System.out.println("Wrong Date Format :" + startTime);
                return badRequest("Wrong Date Format :" + startTime);
            }
        }

        if (!endTime.isEmpty()) {
            try {
                dataSetEndTime = simpleDateFormat.parse(endTime);
                Date min = new Date(0);
                Date max = new Date();
                if (dataSetEndTime.before(min)) {
                    dataSetEndTime = min;
                } else if (dataSetEndTime.after(max)) {
                    dataSetEndTime = max;
                }
            } catch (ParseException e) {
                System.out.println("Wrong Date Format :" + endTime);
                return badRequest("Wrong Date Format :" + endTime);
            }
        }
    } catch (IllegalStateException e) {
        e.printStackTrace();
        Application.flashMsg(APICall.createResponse(ResponseType.CONVERSIONERROR));
    } catch (Exception e) {
        e.printStackTrace();
        Application.flashMsg(APICall.createResponse(ResponseType.UNKNOWN));
    }
    List<DataSet> response = DataSet.queryDataSet(dataSetName, agency, instrument, physicalVariable,
            gridDimension, dataSetStartTime, dataSetEndTime);
    return ok(dataSetList.render(response, dataSetForm));
}

From source file:com.saiton.ccs.validations.FormatAndValidate.java

private static boolean doesTheDateFallsBetween(Date from, Date to, Date date) {

    return (date.equals(from) || date.equals(to) || (date.after(from) && date.before(to)));

}

From source file:com.discovery.darchrow.date.DateExtensionUtil.java

/**
 * ?(??),<br>//from  w  ww. j av a  2 s .c o  m
 * ?? <code>00:00:00.000</code>
 * 
 * <pre>
 * getIntervalDayList("2011-03-5 23:31:25.456","2011-03-10 01:30:24.895", DatePattern.commonWithTime)
 * 
 * return
 * 2011-03-05 00:00:00
 * 2011-03-06 00:00:00
 * 2011-03-07 00:00:00
 * 2011-03-08 00:00:00
 * 2011-03-09 00:00:00
 * 2011-03-10 00:00:00
 * 
 * </pre>
 * 
 * @param fromDateString
 *            
 * @param toDateString
 *            ?
 * @param datePattern
 *            ? {@link DatePattern}
 * @return the interval day list
 * @see DateUtil#getIntervalDay(Date, Date)
 */
public static List<Date> getIntervalDayList(String fromDateString, String toDateString, String datePattern) {
    List<Date> dateList = new ArrayList<Date>();
    //***************************************************************/
    Date beginDate = DateUtil.string2Date(fromDateString, datePattern);
    Date endDate = DateUtil.string2Date(toDateString, datePattern);
    // ******?********
    Date beginDateReset = CalendarUtil.resetDateByDay(beginDate);
    Date endDateReset = CalendarUtil.resetDateByDay(endDate);
    //***************************************************************/
    // 
    int intervalDay = DateUtil.getIntervalDay(beginDateReset, endDateReset);
    //***************************************************************/
    Date minDate = beginDateReset;
    if (beginDateReset.equals(endDateReset)) {
        minDate = beginDateReset;
    } else if (beginDateReset.before(endDateReset)) {
        minDate = beginDateReset;
    } else {
        minDate = endDateReset;
    }
    //***************************************************************/
    dateList.add(minDate);
    //***************************************************************/
    if (intervalDay > 0) {
        for (int i = 0; i < intervalDay; ++i) {
            dateList.add(DateUtil.addDay(minDate, i + 1));
        }
    }
    return dateList;
}

From source file:cz.cvut.kbss.wpa.validator.MatchDateValidator.java

public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException {
    Date d = (Date) o;
    if (d.before(new Date())) {
        throw new ValidatorException(new FacesMessage(FacesUtil.getMessage("wrongPropDate")));
    }/*from  w  w w.  j  av  a  2 s . co  m*/

}

From source file:eu.europa.esig.dss.validation.process.AdESTValidation.java

private static Date getLatestDate(Date firstDate, final Date secondDate) {

    if ((firstDate != null) && (secondDate != null)) {
        if (firstDate.before(secondDate)) {
            firstDate = secondDate;//  w  w w .  jav  a 2 s. c  om
        }
    } else if (secondDate != null) {
        firstDate = secondDate;
    }
    return firstDate;
}

From source file:com.liferay.jenkins.tools.BeforeTimestampMatcher.java

@Override
public boolean matches(Build jenkinsBuild) {
    Date date = new Date(jenkinsBuild.getTimestamp());

    if (date.before(end)) {
        return true;
    }//from   w ww  .ja v a 2  s .  c o m

    return false;
}

From source file:com.liferay.jenkins.tools.BetweenTimestampsMatcher.java

private void setTimestamps(Date timestamp1, Date timestamp2) {
    if (timestamp1.before(timestamp2)) {
        this.start = timestamp1;
        this.end = timestamp2;
    } else {//from   w  ww . java2 s . co m
        this.start = timestamp2;
        this.end = timestamp1;
    }

    logger.debug("Matching builds between {} and {}", start, end);
}