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.joinsystem.goku.common.utils.DateUtil.java

/**
 * //from   w ww. j  ava  2  s  . c  o  m
 * 
 * @param
 *            start <br>
 * @param
 *            end ?<br>
 * @return int
 */
public static int diffMonth(Date start, Date end) {
    if (start.after(end)) {
        Date t = start;
        start = end;
        end = t;
    }
    Calendar startCalendar = Calendar.getInstance();
    startCalendar.setTime(start);
    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(end);
    Calendar temp = Calendar.getInstance();
    temp.setTime(end);
    temp.add(Calendar.DATE, 1);

    int year = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR);
    int month = endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);

    if ((startCalendar.get(Calendar.DATE) == 1) && (temp.get(Calendar.DATE) == 1)) {
        return year * 12 + month + 1;
    } else if ((startCalendar.get(Calendar.DATE) != 1) && (temp.get(Calendar.DATE) == 1)) {
        return year * 12 + month;
    } else if ((startCalendar.get(Calendar.DATE) == 1) && (temp.get(Calendar.DATE) != 1)) {
        return year * 12 + month;
    } else {
        return (year * 12 + month - 1) < 0 ? 0 : (year * 12 + month);
    }
}

From source file:com.google.sampling.experiential.server.EventRetriever.java

public static void sortEvents(List<Event> greetings) {
    Comparator<Event> dateComparator = new Comparator<Event>() {
        @Override/*  w w w .  ja  v a2 s  . co  m*/
        public int compare(Event o1, Event o2) {
            Date when1 = o1.getWhen();
            Date when2 = o2.getWhen();
            if (when1 == null || when2 == null) {
                return 0;
            } else if (when1.after(when2)) {
                return -1;
            } else if (when2.after(when1)) {
                return 1;
            }
            return 0;
        }
    };
    Collections.sort(greetings, dateComparator);
}

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

public static boolean doesDate1GraterThanDate2(Date toCheckFrom, Date toCheckTo) {
    if (toCheckFrom == null || toCheckTo == null) {
        return false;
    } else {/*from www .  j a  v  a2 s  .  c  o m*/
        if (toCheckFrom.after(toCheckTo)) {
            return false;
        } else {
            return true;
        }
    }
}

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 {//  w  w  w.  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:it.eng.spagobi.tools.downloadFiles.service.DownloadZipAction.java

/** Search all files in directory wich in their name has timestamp from begin date to end date
 * /*from ww  w  .j  a  va 2  s.  com*/
 * @param vector
 * @param dir
 * @param beginDate
 * @param endDate
 * @return
 * @throws ParseException
 */

static public Vector<File> searchDateFiles(File dir, Date beginDate, Date endDate, String prefix) {

    Vector<File> toReturn = new Vector<File>();

    // if directory ha files 
    if (dir.isDirectory() && dir.list() != null && dir.list().length != 0) {

        //         serach only files starting with prefix

        // get sorted array
        File[] files = getSortedArray(dir, prefix);

        if (files == null) {
            throw new SpagoBIServiceException(SERVICE_NAME, "Missing files in specified interval");
        }

        // cycle on all files
        boolean exceeded = false;
        for (int i = 0; i < files.length && !exceeded; i++) {
            File childFile = files[i];

            // extract date from file Name
            Date fileDate = null;
            try {
                fileDate = extractDate(childFile.getName(), prefix);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                logger.error("error in parsing log file date, file will be ignored!", e);
                continue;
            }

            // compare beginDate and timeDate, if previous switch file, if later see end date
            // compare then end date, if previous then endDate add file, else exit

            // if fileDate later than begin Date
            if (fileDate != null && fileDate.after(beginDate)) {
                // if end date later than file date
                if (endDate.after(fileDate)) {
                    // it is in the interval, add to list!
                    toReturn.add(childFile);
                } else { // if file date is later then end date, we are exceeding interval
                    exceeded = true;
                }

            }
        }
    }
    return toReturn;
}

From source file:org.openmrs.module.pharmacyapi.api.prescription.util.NewPrescriptionItemGenerator.java

@Override
public boolean isOrderExpired(final PrescriptionItem item, final Date consultationDate) {

    return consultationDate.after(this.getExpirationDateMinus2Days(item));
}

From source file:edu.harvard.i2b2.fhirserver.ejb.AuthenticationService.java

private boolean isExpired(Date inputDate) {

    Date current = new Date();
    boolean result = current.after(inputDate) ? true : false;
    logger.info("current Date:" + current.toGMTString() + "\ninputDate:" + inputDate.toGMTString()
            + "\nisExpired?:" + result);
    return result;
}

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

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

    if ((firstDate != null) && (secondDate != null)) {
        if (firstDate.after(secondDate)) {
            firstDate = secondDate;//  ww  w . j  a  v  a2  s  . com
        }
    } else if (secondDate != null) {
        firstDate = secondDate;
    }
    return firstDate;
}

From source file:com.ibm.domino.das.resources.DocumentResource.java

static private void ifUnmodifiedSince(Document document, final String ifUnmodifiedSince) throws NotesException {
    DateTime lastModifiedDateTime = document.getLastModified();

    if (lastModifiedDateTime != null) {
        Date lastModifiedDate = lastModifiedDateTime.toJavaDate();
        if (lastModifiedDate != null) {
            // Formats the given date according to the RFC 1123 pattern. 
            String lastModifiedHeader = org.apache.http.impl.cookie.DateUtils.formatDate(lastModifiedDate);
            if (lastModifiedHeader != null) {
                if (ifUnmodifiedSince != null) {
                    if (!ifUnmodifiedSince.equalsIgnoreCase(lastModifiedHeader)) {
                        try {
                            Date ifUnmodifiedSinceDate = org.apache.http.impl.cookie.DateUtils
                                    .parseDate(ifUnmodifiedSince);
                            if (lastModifiedDate.after(ifUnmodifiedSinceDate)) {
                                throw new WebApplicationException(Response.Status.PRECONDITION_FAILED);
                            }/*from w w  w.  j ava 2 s  . c  o  m*/
                        } catch (DateParseException e) {
                            throw new WebApplicationException(Response.Status.PRECONDITION_FAILED);
                        }
                    }
                }
            }
        }
    }
}

From source file:com.china317.gmmp.gmmp_report_analysis.App.java

private static void analysisBanche(String yyyyMMdd, ApplicationContext context) {
    try {//from w  w  w  .ja  v a 2 s .c  om
        String businessType = "2";

        // System.out.println("[classpath]"+System.getProperty("java.class.path"));//classpaht
        // System.out.println("[path]"+System.getProperty("user.dir"));//?

        log.info("[get baseVehicle begin---------]");
        VehicleDao vehicleDao = (VehicleDao) context.getBean("vehicleDao");
        List<Vehicle> vehs = vehicleDao.getBaseVehicleByDate(yyyyMMdd, businessType);

        List<List<Vehicle>> list_tm = ListUtil.splitList(vehs, 400);
        log.info("[get baseVehicle end1---------],vehicle total:" + vehs.size());
        log.info("[get baseVehicle end2---------],list_tm total:" + list_tm.size());
        for (List<Vehicle> vls : list_tm) {
            Map<String, Vehicle> vehMap = new HashMap<String, Vehicle>();

            log.info("[code set init------]");
            HashSet<String> codes = new HashSet<String>();
            for (Vehicle v : vls) {
                codes.add(v.getCode());
                vehMap.put(v.getCode(), v);
            }

            log.info("[code set end------]" + "setSize:" + vehMap.size());
            List<VehicleLocate> list = new ArrayList<VehicleLocate>();
            if (codes.size() > 0) {
                VehicleLocateDao vehicleLocateDao_gmmpraw = (VehicleLocateDao) context
                        .getBean("vehicleLocateDaoGmmpRaw");
                list = vehicleLocateDao_gmmpraw.findHistoryByParams(yyyyMMdd, codes);
                log.info("[this time total Points Size]:" + list.size());
            }

            Map<String, List<VehicleLocate>> map = new HashMap<String, List<VehicleLocate>>();
            for (VehicleLocate entity : list) {
                if (entity.getGpsSpeed() < 160) {
                    // businessType
                    Vehicle tmpV = vehMap.get(entity.getCode());
                    entity.setBusinessType(tmpV.getBusinessType());
                    List<VehicleLocate> records = map.get(entity.getCode());
                    if (records == null) {
                        records = new ArrayList<VehicleLocate>();
                    }
                    long lastlong = DateTime.accountTime3(entity.getGpsTime(), entity.getGetTime());
                    if (lastlong <= 10 * 60) {
                        records.add(entity);
                    }
                    map.put(entity.getCode(), records);
                }

            }

            log.info("analysis begin ,total:" + map.size());

            Iterator<String> it = map.keySet().iterator();
            while (it.hasNext()) {
                String key = it.next();
                List<VehicleLocate> tmps = map.get(key);
                log.info("analysis vehicle code:" + key + "sort list begin, list size:" + tmps.size());
                Collections.sort(tmps, new Comparator<VehicleLocate>() {
                    public int compare(VehicleLocate o1, VehicleLocate o2) {
                        Date d1 = o1.getGpsTime();
                        Date d2 = o2.getGpsTime();
                        if (d1.after(d2)) {
                            return 1;
                        } else if (d1.before(d2)) {
                            return -1;
                        } else {
                            return 0;
                        }
                    }
                });
                log.info("analysis vehicle code:" + key + "sort list end");

                log.info("analysis vehicle code:" + key + "OVERSPEED OFFLINE ANALYSIS begin");
                for (int i = 0; i < tmps.size(); i++) {
                    VehicleLocate e = tmps.get(i);
                    AreaAddProcessor.addAreaRuleInfo(e);
                    /*
                     * log.info("[vehcilelocate properties]" + e.getCode() +
                     * "; gpstime:" + e.getGpsTime() + "; gpsSpeed:" +
                     * e.getGpsSpeed() + "; businessType:" +
                     * e.getBusinessType() + "; lon:" + e.getLon() +
                     * "; lat:" + e.getLat() + "; acc:" + e.getACCState());
                     */
                    PtmAnalysisImp.getInstance().overSpeedAnalysis(e);
                    // PtmAnalysisImp.getInstance().offlineAnalysis(e,
                    // yyyyMMdd);

                    // ?
                    PtmAnalysisImp.getInstance().putLastRecord(e);
                }

                log.info("analysis vehicle code:" + key + "OVERSPEED OFFLINE ANALYSIS end");

                log.info("result: overspeed:" + PtmAnalysisImp.getInstance().getOverSpeedRecordsSize()
                        + "; offline:" + PtmAnalysisImp.getInstance().getOfflineRecordsSize());
                // PtmAnalysisImp.getInstance().clear();
            }
            // OverSpeedRecordsStoreIntoDB(PtmAnalysisImp.getInstance()
            // .getOverSpeedRecords(), context);
            PtmOverSpeedRecordsStoreIntoDB(PtmAnalysisImp.getInstance().getOverSpeedRecords(), context);
        }

        log.info("analysis end");

        log.info("[Ptm ended]");
    } catch (Exception e) {
        log.error(e);
    }
}