List of usage examples for java.util Date before
public boolean before(Date when)
From source file:com.aurel.track.fieldType.bulkSetters.DateBulkSetter.java
private static void calculateOffset(BulkTranformContext bulkTranformContext, Integer fieldID, Integer parameterCode, Object targetValue, boolean earliest) { List<TWorkItemBean> selectedWorkItems = bulkTranformContext.getSelectedWorkItems(); Map<Integer, Object> valueCache = bulkTranformContext.getValueCache(); Date targetDate = null;//from www .j av a2 s. co m try { targetDate = (Date) targetValue; } catch (Exception e) { LOGGER.warn("Converting the target value " + targetValue + " to Date failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (targetDate == null || selectedWorkItems == null) { //set to 0 to mark it as calculated (avoid finding the offset for each workItem). 0 means no change anyway valueCache.put(fieldID, Integer.valueOf(0)); return; } Date extremeDate = null; for (TWorkItemBean workItemBean : selectedWorkItems) { Object value = workItemBean.getAttribute(fieldID, parameterCode); if (value != null) { Date actualDate = (Date) value; if (extremeDate == null) { extremeDate = actualDate; } else { if ((earliest && actualDate.before(extremeDate)) || !earliest && actualDate.after(extremeDate)) { extremeDate = actualDate; } } } } if (extremeDate == null) { //set to 0 to mark it as calculated (avoid finding the offset for each workItem). 0 means no change anyway valueCache.put(fieldID, Integer.valueOf(0)); } else { Calendar targetCalendar = Calendar.getInstance(); targetCalendar.setTime(targetDate); Calendar extremeCalendar = Calendar.getInstance(); extremeCalendar.setTime(extremeDate); long diff = targetCalendar.getTimeInMillis() - extremeCalendar.getTimeInMillis(); //daylight saving correction double days = diff * 1.0 / (1000 * 60 * 60 * 24); int intDays = (int) Math.round(days); valueCache.put(fieldID, Integer.valueOf(intDays)); } }
From source file:edu.stanford.muse.email.CalendarUtil.java
/** intervals must be sorted, start from before the earliest date, and end after the latest date */ public static int[] computeHistogram(List<Date> dates, List<Date> intervals, boolean ignoreInvalidDates) { if (intervals == null || intervals.size() == 0) return new int[0]; int nIntervals = intervals.size() - 1; int[] counts = new int[nIntervals]; if (ignoreInvalidDates) { int count = 0; List<Date> newDates = new ArrayList<Date>(); for (Date d : dates) if (!EmailFetcherThread.INVALID_DATE.equals(d)) newDates.add(d);/*from www . j a v a 2s. c o m*/ else count++; dates = newDates; if (count > 0) log.info(count + " invalid date(s) ignored"); } if (dates.size() == 0) return counts; Collections.sort(dates); Date firstDate = dates.get(0); Date lastDate = dates.get(dates.size() - 1); // intervals are assumed to be already sorted if (firstDate.before(intervals.get(0))) throw new RuntimeException("INTERNAL ERROR: invalid dates, first date " + formatDateForDisplay(firstDate) + " before intervals start " + formatDateForDisplay(intervals.get(0)) + ", aborting histogram computation"); if (lastDate.after(intervals.get(intervals.size() - 1))) throw new RuntimeException("INTERNAL ERROR: invalid dates, last date " + formatDateForDisplay(firstDate) + " after intervals end " + formatDateForDisplay(intervals.get(intervals.size() - 1)) + ", aborting histogram computation"); int currentInterval = 0; int thisIntervalCount = 0; // running count which we are accumulating into the current interval // no need to track currentIntervalStart explicitly Date currentIntervalEnd = intervals.get(currentInterval + 1); // we'll run down the sorted dates, counting dates in each interval for (Date currentDate : dates) { if (currentDate.after(currentIntervalEnd)) { // we're done with current interval, commit its count counts[currentInterval] = thisIntervalCount; // find the next interval, skip over till current Date is before the interval end do { currentInterval++; currentIntervalEnd = intervals.get(currentInterval + 1); } while (currentDate.after(currentIntervalEnd)); // now current date is before the current interval end, so we have the new interval reflected in currentIntervalEnd // count currentDate in this interval thisIntervalCount = 1; } else thisIntervalCount++; // still not reached end of interval } // the last interval's end was not exceeded, so set up its count here counts[currentInterval] = thisIntervalCount; return counts; }
From source file:com.inmobi.messaging.consumer.util.TestUtil.java
public static void prepareExpectedDeltaPck(Date fromTime, Date toTime, Map<Integer, PartitionCheckpoint> expectedDeltaPck, FileStatus file, Path streamDir, Set<Integer> partitionMinList, PartitionCheckpointList partitionCheckpointList, boolean isStart, boolean isFileCompleted) { Map<Integer, Date> chkTimeStampMap = new HashMap<Integer, Date>(); // prepare a checkpoint map prepareChkpointTimeMap(chkTimeStampMap, partitionMinList, partitionCheckpointList); Calendar current = Calendar.getInstance(); current.setTime(fromTime);//from w w w . j ava2 s . c o m int lineNum; if (isFileCompleted) { lineNum = -1; } else { lineNum = 0; } if (isStart) { Calendar hourCal = Calendar.getInstance(); hourCal.setTime(fromTime); hourCal.add(Calendar.MINUTE, 60); Date hourTime = hourCal.getTime(); while (current.getTime().before(hourTime)) { int minute = current.get(Calendar.MINUTE); if (partitionMinList.contains(minute)) { Date chkTime = chkTimeStampMap.get(minute); if (chkTime == null || chkTime.before(current.getTime())) { expectedDeltaPck.put(Integer.valueOf(minute), new PartitionCheckpoint( DatabusStreamWaitingReader.getHadoopStreamFile(streamDir, current.getTime()), lineNum)); } } current.add(Calendar.MINUTE, 1); } } if (!isStart) { current.add(Calendar.MINUTE, 1); while (current.getTime().before(toTime)) { int minute = current.get(Calendar.MINUTE); if (partitionMinList.contains(minute)) { Date chkTime = chkTimeStampMap.get(minute); if (chkTime == null || !chkTime.after(current.getTime())) { expectedDeltaPck.put(Integer.valueOf(minute), new PartitionCheckpoint( DatabusStreamWaitingReader.getHadoopStreamFile(streamDir, current.getTime()), -1)); } } current.add(Calendar.MINUTE, 1); } } current.setTime(fromTime); if (file != null) { int minute = current.get(Calendar.MINUTE); expectedDeltaPck.put(Integer.valueOf(minute), new PartitionCheckpoint(DatabusStreamWaitingReader.getHadoopStreamFile(file), -1)); } else { int minute = current.get(Calendar.MINUTE); expectedDeltaPck.put(Integer.valueOf(minute), new PartitionCheckpoint( DatabusStreamWaitingReader.getHadoopStreamFile(streamDir, current.getTime()), -1)); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.legacyExcel.importer.sheets.SheetImporter.java
public static boolean isValidRuntimePeriod(Date start, Date end) { boolean result = true; if (start != null && end != null && end.before(start)) { result = false;// w ww. j a v a2 s. c o m } return result; }
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 ww w . j a va 2 s . co 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:DateUtil.java
/** * Tells you if the date part of a datetime is in a certain time range. *//*from w ww . ja va 2 s .c o m*/ public static boolean isTimeInRange(java.sql.Time start, java.sql.Time end, java.util.Date d) { d = new java.sql.Time(d.getHours(), d.getMinutes(), d.getSeconds()); if (start == null || end == null) { return false; } if (start.before(end) && (!(d.after(start) && d.before(end)))) { return false; } if (end.before(start) && (!(d.after(end) || d.before(start)))) { return false; } return true; }
From source file:ee.ria.xroad.asyncdb.AsyncDBIntegrationTest.java
/** * During validation we assume that expected date is never before actual. * * @param expected - expected date./*w w w . j av a2s . c o m*/ * @param actual - actual date. * @return - whether expected and actual dates are equivalent. */ private static boolean areDatesEquivalent(Date expected, Date actual) { if (expected == null || actual == null) { return true; } return !expected.before(actual); }
From source file:com.sccl.attech.common.utils.DateUtils.java
/** * ??// w ww. j av a2 s . c om * @param startTime * @param endTime * @return * @throws ParseException */ public static Boolean isBetweenTime(Date startTime, Date endTime) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String current = formatter.format(new Date()); //? Date start; Date end; Date currentTime; try { start = formatter.parse(formatter.format(startTime)); end = formatter.parse(formatter.format(endTime)); currentTime = formatter.parse(current); return ((currentTime.before(end) && currentTime.after(start)) || currentTime.equals(start) || currentTime.equals(end)); } catch (ParseException e) { e.printStackTrace(); } return false; }
From source file:mitm.common.security.crl.CRLUtils.java
/** * Returns 0 if crl and otherCRL have similar validity (ie no one is newer than the other), * > 0 if crl is newer than otherCRL and < 0 if crl is older than otherCRL *///from www .j a va 2 s . c o m public static int compare(X509CRL crl, X509CRL otherCRL) throws IOException, MissingDateException { BigInteger crlNumber = X509CRLInspector.getCRLNumber(crl); BigInteger otherCRLNumber = X509CRLInspector.getCRLNumber(crl); Date thisUpdate = crl.getThisUpdate(); Date otherThisUpdate = otherCRL.getThisUpdate(); if (thisUpdate == null || otherThisUpdate == null) { throw new MissingDateException("One of the CRLs has a missing thisUpdate."); } int cmp; if (crlNumber != null && otherCRLNumber != null) { cmp = crlNumber.compareTo(otherCRLNumber); if (cmp > 0) { if (thisUpdate.before(otherThisUpdate)) { logger.warn("According to CRL numbers a new CRL is found but thisUpdate is older."); } logger.debug("The CRL number is bigger and is therefore more recent."); } else if (cmp == 0) { /* * same CRL number but thisUpdate can be newer */ cmp = thisUpdate.compareTo(otherThisUpdate); if (cmp > 0) { logger.debug("The CRL numbers are equal but thisUpdate is newer."); } } else { if (thisUpdate.after(otherThisUpdate)) { logger.warn("According to CRL numbers this not a new CRL but thisUpdate is newer."); } } } else { /* * no CRL number so compare thisUpdate */ cmp = thisUpdate.compareTo(otherThisUpdate); if (cmp > 0) { logger.debug("A more recent CRL is found."); } } return cmp; }
From source file:com.aurel.track.fieldType.runtime.system.text.SystemDateRT.java
/** * Get the earliest start date or the latest endDate of all children * @param parentID/*from w w w. j a va 2 s. c om*/ * @param earliest * @return */ private static Date getOutermostChildDate(Integer parentID, Integer fieldID, boolean earliest) { Date date = null; List<TWorkItemBean> siblingWorkItemBeans = ItemBL.getChildren(parentID); if (siblingWorkItemBeans != null && !siblingWorkItemBeans.isEmpty()) { for (TWorkItemBean siblingWorkItemBean : siblingWorkItemBeans) { Date siblingDate = (Date) siblingWorkItemBean.getAttribute(fieldID); if (siblingDate != null && (date == null || (earliest && siblingDate.before(date)) || (!earliest && siblingDate.after(date)))) { date = siblingDate; } } } return date; }