List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:com.photon.phresco.framework.rest.api.BuildInfoService.java
public int compare(BuildInfo buildInfo1, BuildInfo buildInfo2) { DateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss"); Date buildTime1 = new Date(); Date buildTime2 = new Date(); try {/*from w w w .ja va 2s . c o m*/ buildTime1 = (Date) formatter.parse(buildInfo1.getTimeStamp()); buildTime2 = (Date) formatter.parse(buildInfo2.getTimeStamp()); } catch (ParseException e) { } return buildTime2.compareTo(buildTime1); }
From source file:org.sakaiproject.signup.restful.SignupEvent.java
/** * This method will check if the event/meeting is already expired * /* w w w . j av a 2s . co m*/ * @return true if the event/meeting is expired */ public boolean isMeetingExpired() { Date today = new Date(); // pastMeeting => today>endDate => value>0 int value = today.compareTo(endTime); return value > 0; }
From source file:org.egov.stms.web.controller.masters.SewerageRateMasterController.java
@RequestMapping(value = "/fromDateValidationWithLatestActiveRecord", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody// w ww . jav a 2 s . co m public String getLatestActiveFromDate(@RequestParam("propertyType") final PropertyType propertyType, @RequestParam("fromDate") final Date fromDate) { final SimpleDateFormat newFormat = new SimpleDateFormat("dd-MM-yyyy"); final List<SewerageRatesMaster> existingsewerageRatesMasterList = sewerageRatesMasterService .getLatestActiveRecord(propertyType, true); if (!existingsewerageRatesMasterList.isEmpty() && fromDate != null) { final SewerageRatesMaster existingActiveSewerageRatesObject = existingsewerageRatesMasterList.get(0); if (fromDate.compareTo(existingActiveSewerageRatesObject.getFromDate()) < 0) return newFormat.format(existingActiveSewerageRatesObject.getFromDate()); } return "true"; }
From source file:org.openregistry.core.domain.jpa.JpaActivationKeyImpl.java
public JpaActivationKeyImpl(final Date startDate, final Date endDate) { Assert.isTrue((startDate != null && endDate != null) || (startDate == null && endDate == null), "Both start and end date must be specified, or they must both be null to use the default value."); if (startDate == null && endDate == null) { final Calendar calendar = Calendar.getInstance(); final Date localStartDate = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, 10); final Date localEndDate = calendar.getTime(); this.start = localStartDate; this.end = localEndDate; } else {//from w w w. j av a 2s . c o m Assert.isTrue(endDate.compareTo(startDate) > 0, "The End Date MUST be after the Start Date."); this.start = new Date(startDate.getTime()); this.end = new Date(endDate.getTime()); } this.value = constructNewValue(); }
From source file:org.egov.stms.web.controller.masters.SewerageRateMasterController.java
@RequestMapping(value = "update/{id}", method = POST) public String update(@ModelAttribute final SewerageRatesMaster sewerageRatesMaster, @PathVariable final Long id, final Model model, final RedirectAttributes redirectAttrs, final BindingResult errors) throws ParseException { final SimpleDateFormat newFormat = new SimpleDateFormat("dd-MM-yyyy"); final SewerageRatesMaster ratesMaster = sewerageRatesMasterService.findBy(id); final String todaysdate = newFormat.format(new Date()); final String effectiveFromDate = newFormat.format(ratesMaster.getFromDate()); final Date currentDate = newFormat.parse(todaysdate); final Date effectiveDate = newFormat.parse(effectiveFromDate); if (getAppconfigValue()) sewerageMasterDataValidator.validateSewerageMonthlyRateUpdate(sewerageRatesMaster, errors); if (errors.hasErrors()) { model.addAttribute("sewerageRatesMaster", sewerageRatesMaster); if (getAppconfigValue()) return "seweragemonthlyRates-update"; else/*from www . jav a2s.co m*/ return "sewerageRates-update"; } if (effectiveDate.compareTo(currentDate) < 0) { model.addAttribute(MESSAGE, "msg.seweragerate.modification.rejected"); return "sewerageRates-update"; } if (getAppconfigValue()) { final List<SewerageRatesMasterDetails> existingSewerageDetailList = new ArrayList<>(); if (sewerageRatesMaster != null && !sewerageRatesMaster.getSewerageDetailmaster().isEmpty()) existingSewerageDetailList.addAll(ratesMaster.getSewerageDetailmaster()); if (sewerageRatesMaster != null && sewerageRatesMaster.getSewerageDetailmaster() != null) sewerageRatesMasterService.updateSewerageRateMaster(sewerageRatesMaster, ratesMaster, existingSewerageDetailList); } else { ratesMaster.setMonthlyRate(sewerageRatesMaster.getMonthlyRate()); sewerageRatesMasterService.update(ratesMaster); } redirectAttrs.addFlashAttribute(MESSAGE, "msg.seweragemonthlyrate.update.success"); return SEWERAGE_RATES_SUCCESS_PAGE + id; }
From source file:ju.ehealthservice.search.Search.java
public List<String> getFileNames(String from, String to) { if (patientExists()) { try {/*from w ww .j av a 2 s.com*/ Date fromDate = Constants.small.parse(from); Date toDate = Constants.small.parse(to); if (fromDate.equals(toDate)) { toDate = DateUtils.addSeconds(toDate, 86399); } for (File listOfFile : listOfFiles) { if (listOfFile.isFile()) { if (!listOfFile.getName().equals("metadata.xml")) { String originalName = listOfFile.getName(); String fileName = originalName.split("_", 2)[1]; System.out.println("File name is " + fileName); Date date = Constants.sdf.parse(fileName); if (fromDate.compareTo(date) * toDate.compareTo(date) < 0) { files.add(originalName); } } } } } catch (Exception e) { e.printStackTrace(); } } return trimFileExtension(files); }
From source file:com.k42b3.neodym.Http.java
public String request(int method, String url, Map<String, String> header, String body, boolean signed) throws Exception { // check cache (only GET) String cacheKey = url;//w ww .j av a2 s . c o m if (method == Http.GET) { Cache cache = cacheManager.get(cacheKey); if (cache != null) { logger.info("Found cache for " + cacheKey + " expires in " + DateFormat.getInstance().format(cache.getExpire())); return cache.getResponse(); } } // build request HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 6000); DefaultHttpClient httpClient = new DefaultHttpClient(httpParams); HttpRequestBase httpRequest; if (method == Http.GET) { httpRequest = new HttpGet(url); } else if (method == Http.POST) { httpRequest = new HttpPost(url); if (body != null && !body.isEmpty()) { ((HttpPost) httpRequest).setEntity(new StringEntity(body)); } } else { throw new Exception("Invalid request method"); } // add headers if (header != null) { Set<String> keys = header.keySet(); for (String k : keys) { httpRequest.addHeader(k, header.get(k)); } } // sign request if (oauth != null && signed) { oauth.signRequest(httpRequest); } // execute request logger.info("Request: " + httpRequest.getRequestLine().toString()); HttpResponse httpResponse = httpClient.execute(httpRequest); logger.info("Response: " + httpResponse.getStatusLine().toString()); HttpEntity entity = httpResponse.getEntity(); String responseContent = EntityUtils.toString(entity); // log traffic if (trafficListener != null) { TrafficItem trafficItem = new TrafficItem(); trafficItem.setRequest(httpRequest); trafficItem.setRequestContent(body); trafficItem.setResponse(httpResponse); trafficItem.setResponseContent(responseContent); trafficListener.handleRequest(trafficItem); } // check status code int statusCode = httpResponse.getStatusLine().getStatusCode(); if (!(statusCode >= 200 && statusCode < 300)) { if (!responseContent.isEmpty()) { String message = responseContent.length() > 128 ? responseContent.substring(0, 128) + "..." : responseContent; throw new Exception(message); } else { throw new Exception("No successful status code"); } } // assign last request/response lastRequest = httpRequest; lastResponse = httpResponse; // cache response if expires header is set if (method == Http.GET) { Date expire = null; Header[] headers = httpResponse.getAllHeaders(); for (int i = 0; i < headers.length; i++) { if (headers[i].getName().toLowerCase().equals("expires")) { try { expire = DateFormat.getInstance().parse(headers[i].getValue()); } catch (Exception e) { } } } if (expire != null && expire.compareTo(new Date()) > 0) { Cache cache = new Cache(cacheKey, responseContent, expire); cacheManager.add(cache); logger.info("Add to cache " + cacheKey + " expires in " + DateFormat.getInstance().format(expire)); } } return responseContent; }
From source file:org.apache.oozie.command.coord.CoordMaterializeTransitionXCommand.java
private void updateJobMaterializeInfo(CoordinatorJobBean job) throws CommandException { job.setLastActionTime(endMatdTime);//from ww w . j a v a 2s. co m job.setLastActionNumber(lastActionNumber); // if the job endtime == action endtime, we don't need to materialize this job anymore Date jobEndTime = job.getEndTime(); if (job.getStatus() == CoordinatorJob.Status.PREP) { LOG.info("[" + job.getId() + "]: Update status from " + job.getStatus() + " to RUNNING"); job.setStatus(Job.Status.RUNNING); } job.setPending(); if (jobEndTime.compareTo(endMatdTime) <= 0) { LOG.info("[" + job.getId() + "]: all actions have been materialized, set pending to true"); // set doneMaterialization to true when materialization is done job.setDoneMaterialization(); } job.setStatus(StatusUtils.getStatus(job)); LOG.info("Coord Job status updated to = " + job.getStatus()); job.setNextMaterializedTime(endMatdTime); }
From source file:org.atomserver.core.dbstore.dao.EntriesDAOTest.java
public void testSort() throws Exception { // COUNT/*from w ww.j a v a 2 s.c o m*/ BaseServiceDescriptor serviceDescriptor = new BaseServiceDescriptor(workspace); int startCount = entriesDAO.getTotalCount(serviceDescriptor); log.debug("startCount = " + startCount); String sysId = "acme"; int propIdSeed = 34300; Locale locale = LocaleUtils.toLocale("en"); Date[] lastMod = new Date[3]; long lnow = (entriesDAO.selectSysDate()).getTime(); lastMod[0] = new Date(lnow); lastMod[1] = new Date(lnow - 100000L); lastMod[2] = new Date(lnow - 200000L); log.debug("lastMod:: " + lastMod[0] + " " + lastMod[1] + " " + lastMod[2]); // INSERT int numRecs = 20; Date zeroDate = new Date(0L); try { for (int ii = 0; ii < numRecs; ii++) { EntryMetaData entryIn = new EntryMetaData(); entryIn.setWorkspace("widgets"); entryIn.setCollection(sysId); entryIn.setLocale(locale); String propId = "" + (propIdSeed + ii); entryIn.setEntryId(propId); entryIn.setUpdatedDate(lastMod[(ii % 3)]); entryIn.setPublishedDate(lastMod[(ii % 3)]); entriesDAO.ensureCollectionExists(entryIn.getWorkspace(), entryIn.getCollection()); entriesDAO.insertEntry(entryIn, true, lastMod[(ii % 3)], lastMod[(ii % 3)]); } // COUNT int count = entriesDAO.getTotalCount(serviceDescriptor); assertEquals((startCount + numRecs), count); count = entriesDAO.getCountByLastModified(serviceDescriptor, lastMod[0]); log.debug("+++++++++++++++++++> getCountByLastModified= " + count); assertEquals(7, count); // SORT -- From the begining of time List sortedList = entriesDAO.selectEntriesByLastModified(workspace, null, zeroDate); log.debug("List= " + sortedList); Date lastVal = zeroDate; for (Object obj : sortedList) { EntryMetaData entry = (EntryMetaData) obj; assertTrue(lastVal.compareTo(entry.getUpdatedDate()) <= 0); lastVal = entry.getUpdatedDate(); } // SORT -- from now -- so the List should be empty Thread.sleep(1000); long lnow2 = (entriesDAO.selectSysDate()).getTime(); sortedList = entriesDAO.selectEntriesByLastModified(workspace, null, (new Date(lnow2))); log.debug("List= " + sortedList); assertEquals(0, sortedList.size()); // ============== entriesDAO.updateLastModifiedSeqNumForAllEntries(serviceDescriptor); sortedList = entriesDAO.selectEntriesByLastModified(workspace, null, zeroDate); log.debug("List= " + sortedList); lastVal = zeroDate; for (Object obj : sortedList) { EntryMetaData entry = (EntryMetaData) obj; assertTrue(lastVal.compareTo(entry.getUpdatedDate()) <= 0); lastVal = entry.getUpdatedDate(); // FIXME -- this Should work but does not. // AFAICt there may be something wrong with the updateLastModifiedSeqNumForAllEntries // BUT this code is NOT actually used anywhere in PRD // So I am going to ignore it for now. //assertTrue("[seqNum= " + seqNum + "] !< [entrySeq= " + entry.getUpdateTimestamp(), // seqNum < entry.getUpdateTimestamp()); entry.getUpdateTimestamp(); } } finally { // DELETE some for (int ii = 0; ii < numRecs / 2; ii++) { String propId = "" + (propIdSeed + ii); IRI iri = IRI.create("http://localhost:8080/" + entryURIHelper.constructURIString(workspace, sysId, propId, locale)); EntryTarget entryTarget = entryURIHelper .getEntryTarget(new MockRequestContext(serviceContext, "GET", iri.toString()), true); entriesDAO.obliterateEntry(entryTarget); } // SORT -- From the begining of time List sortedList = entriesDAO.selectEntriesByLastModifiedSeqNum(new BaseFeedDescriptor(workspace, null), zeroDate); log.debug("List= " + sortedList); Date lastVal = zeroDate; for (Object obj : sortedList) { EntryMetaData entry = (EntryMetaData) obj; log.debug("&&&&&COMPARE DATES:: " + lastVal + " " + entry.getUpdatedDate()); assertTrue(lastVal.compareTo(entry.getUpdatedDate()) <= 0); lastVal = entry.getUpdatedDate(); } // DELETE the rest for (int ii = (numRecs / 2 - 1); ii < numRecs; ii++) { String propId = "" + (propIdSeed + ii); IRI iri = IRI.create("http://localhost:8080/" + entryURIHelper.constructURIString(workspace, sysId, propId, locale)); EntryTarget entryTarget = entryURIHelper .getEntryTarget(new MockRequestContext(serviceContext, "GET", iri.toString()), true); entriesDAO.obliterateEntry(entryTarget); } // COUNT Thread.sleep(DB_CATCHUP_SLEEP); // give the DB a chance to catch up int finalCount = entriesDAO.getTotalCount(serviceDescriptor); log.debug("finalCount = " + finalCount); assertEquals(startCount, finalCount); } }
From source file:org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm.java
protected ActionErrors validateDate(String date, String fieldName) { ActionErrors errors = null;/* w w w . java 2s . c o m*/ java.sql.Date sqlDate = null; if (date != null && !date.equals("")) { try { sqlDate = getDateAsSentFromBrowser(date); if (DateUtils.whichDirection(sqlDate) > 0) { errors = new ActionErrors(); errors.add(AccountConstants.ERROR_FUTUREDATE, new ActionMessage(AccountConstants.ERROR_FUTUREDATE, fieldName)); } else if (previousPaymentDate != null && sqlDate.compareTo(previousPaymentDate) < 0) { errors = new ActionErrors(); errors.add(AccountConstants.ERROR_ADJUSTMENT_PREVIOUS_DATE, new ActionMessage(AccountConstants.ERROR_ADJUSTMENT_PREVIOUS_DATE, fieldName)); } else if (nextPaymentDate != null && sqlDate.compareTo(nextPaymentDate) > 0) { errors = new ActionErrors(); errors.add(AccountConstants.ERROR_ADJUSTMENT_NEXT_DATE, new ActionMessage(AccountConstants.ERROR_ADJUSTMENT_NEXT_DATE, fieldName)); } } catch (InvalidDateException ide) { errors = new ActionErrors(); errors.add(AccountConstants.ERROR_INVALIDDATE, new ActionMessage(AccountConstants.ERROR_INVALIDDATE, fieldName)); } } else { errors = new ActionErrors(); errors.add(AccountConstants.ERROR_MANDATORY, new ActionMessage(AccountConstants.ERROR_MANDATORY, fieldName)); } return errors; }