List of usage examples for java.util Date before
public boolean before(Date when)
From source file:com.edgenius.wiki.ext.calendar.service.CalendarServiceImpl.java
/** * Check if this repeat event appear in given period. * @param event//www .ja v a 2 s . c om * @param start * @param end */ @SuppressWarnings("deprecation") private List<CalendarEvent> getRepeatEventsInPeriod(CalendarEvent event, Date start, Date end) { String rule = event.getRepeatRule(); if (StringUtils.isBlank(rule)) return null; //if first event is after scope, then return null if (event.getStart().after(end)) return null; String[] parts = rule.split(","); if (parts.length != 5) { return null; } if (parts[4].length() != 0) { //if end is early than start, then simple return null. try { Date rEnd = ruleDateParser.parse(parts[4]); if (rEnd.before(start)) return null; } catch (ParseException e) { log.error("Unable to parse end date of event " + event.getUid()); } } //parse and calculate according to type, repeat and step int step = NumberUtils.toInt(parts[2]) + 1; List<Date[]> candidates = new ArrayList<Date[]>(); Date evtS = event.getStart(); Date evtE = event.getEnd(); Date candidateS; Date candidateE; if ("yearly".equals(parts[0])) { if ((start.getYear() - evtS.getYear()) % step == 0) { int idx = start.getYear(); do { } while (idx <= end.getYear()); } } else if ("monthly".equals(parts[0])) { } else if ("weekly".equals(parts[0])) { } else if ("daily".equals(parts[0])) { } return null; }
From source file:eu.ggnet.dwoss.report.eao.ReportLineEao.java
private NavigableMap<Date, Revenue> prepare(Date start, Date end, Step step) { NavigableMap<Date, Revenue> result = new TreeMap<>(); Date actual = step.truncate(start); end = step.prepareEnd(end);//from ww w . j a v a 2 s .c om while (actual.before(end)) { result.put(actual, new Revenue()); actual = step.incement(actual); } return result; }
From source file:de.micromata.genome.gwiki.pagelifecycle_1_0.wizard.TimingStepWizardAction.java
/** * Formats the date to internat String repesentation * @param stringDate/* www. ja va2s .c o m*/ * @param hour * @param min * @param sec * @return */ private String formatDate(String stringDate, int hour, int min, int sec) { // if release imeediately then store no timestamp if (isTmImmediately() == true) { return StringUtils.EMPTY; } try { Date date = internalTimestamp.get().parse(stringDate); Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, min); c.set(Calendar.SECOND, sec); Date dateTime = c.getTime(); if (dateTime.before(new Date()) == true) { wikiContext.addValidationError("gwiki.page.articleWizard.error.date.past"); } return GWikiProps.formatTimeStamp(dateTime); } catch (ParseException ex) { wikiContext.addValidationError("gwiki.page.articleWizard.error.date.invalid"); } return StringUtils.EMPTY; }
From source file:com.unispezi.cpanelremotebackup.CPanelRemoteBackup.java
/** * Polls until size of server file does not change anymore * * @param timeoutDate max timestamp until this operation may run * @param backupName backup name on server * @return file size in bytes//from w ww. j a va 2 s . co m * @throws ReadTimeoutException if operation took longer than timeout */ private long waitForBackupSizeToBecomeStable(Date timeoutDate, String backupName) throws ReadTimeoutException { com.unispezi.cpanelremotebackup.tools.Console.print("Polling for backup file size to become stable"); long lastFileSize = 0; long currentFileSize = 0; Date now = new Date(); while (((currentFileSize < minFileBytes) || (currentFileSize != lastFileSize)) && (now.before(timeoutDate))) { com.unispezi.cpanelremotebackup.tools.Console.print("."); FTPFile backupWeStarted = ftp.getFileDetails(backupName); lastFileSize = currentFileSize; currentFileSize = backupWeStarted.getSize(); try { Thread.sleep(pollIntervalSeconds * 1000); } catch (InterruptedException e) { //Do nothing } now = new Date(); } com.unispezi.cpanelremotebackup.tools.Console.println(" " + currentFileSize + " bytes"); if (now.after(timeoutDate)) { throw new ReadTimeoutException("Download of file exceeded timeout"); } return currentFileSize; }
From source file:dk.netarkivet.harvester.scheduler.jobgen.AbstractJobGenerator.java
@Override public int generateJobs(HarvestDefinition harvest) { log.info("Generating jobs for harvestdefinition # " + harvest.getOid()); int jobsMade = 0; final Iterator<DomainConfiguration> domainConfigurations = harvest.getDomainConfigurations(); while (domainConfigurations.hasNext()) { List<DomainConfiguration> subset = new ArrayList<DomainConfiguration>(); while (domainConfigurations.hasNext() && subset.size() < DOMAIN_CONFIG_SUBSET_SIZE) { subset.add(domainConfigurations.next()); }//w ww . ja v a 2 s.com Collections.sort(subset, getDomainConfigurationSubsetComparator(harvest)); if (log.isTraceEnabled()) { log.trace(subset.size() + " domainconfigs now sorted and ready to processing " + "for harvest #" + harvest.getOid()); } jobsMade += processDomainConfigurationSubset(harvest, subset.iterator()); } harvest.setNumEvents(harvest.getNumEvents() + 1); if (!harvest.isSnapShot()) { PartialHarvest focused = (PartialHarvest) harvest; Schedule schedule = focused.getSchedule(); int numEvents = harvest.getNumEvents(); //Calculate next event Date now = new Date(); Date nextEvent = schedule.getNextEvent(focused.getNextDate(), numEvents); //Refuse to schedule event in the past if (nextEvent != null && nextEvent.before(now)) { int eventsSkipped = 0; while (nextEvent != null && nextEvent.before(now)) { nextEvent = schedule.getNextEvent(nextEvent, numEvents); eventsSkipped++; } if (log.isWarnEnabled()) { log.warn("Refusing to schedule harvest definition '" + harvest.getName() + "' in the past. Skipped " + eventsSkipped + " events. Old nextDate was " + focused.getNextDate() + " new nextDate is " + nextEvent); } } //Set next event focused.setNextDate(nextEvent); if (log.isTraceEnabled()) { log.trace("Next event for harvest definition " + harvest.getName() + " happens: " + (nextEvent == null ? "Never" : nextEvent.toString())); } } log.info("Finished generating " + jobsMade + " jobs for harvestdefinition # " + harvest.getOid()); return jobsMade; }
From source file:com.cemeterylistingsweb.services.impl.ViewListingBySubscriberServiceImpl.java
@Override public List<PublishedDeceasedListing> findListingBySubscriber(java.sql.Date subDate, java.sql.Date validDate) { List<PublishedDeceasedListing> publists = publishRepo.findAll(); //find listing by dob List<PublishedDeceasedListing> list = new ArrayList(); for (PublishedDeceasedListing pubListing : publists) { SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Date parsed = null;/* www . ja va2 s. co m*/ try { parsed = format.parse(pubListing.getDateOfDeath()); } catch (ParseException ex) { Logger.getLogger(ViewListingBySubscriberServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } java.sql.Date dod = new java.sql.Date(parsed.getTime()); //Date dod = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(pubListing.getDateOfDeath()); System.out.println(dod); System.out.println(subDate); System.out.println(validDate); if (dod.after(subDate) && dod.before(validDate)) System.out.println(dod); System.out.println("added" + ""); list.add(pubListing); } return list; }
From source file:org.openhealthtools.openatna.web.ErrorController.java
private List<? extends ErrorEntity> query(QueryBean bean) throws AtnaPersistenceException { List<? extends ErrorEntity> ents = null; Date startDate = null;/*from www.ja v a 2s. c om*/ if (bean.getStartDate() != null && bean.getStartDate().length() > 0) { String date = bean.getStartDate(); try { startDate = format.parse(date + " " + bean.getStartHour() + ":" + bean.getStartMin()); } catch (ParseException e) { } } Date endDate = null; if (bean.getEndDate() != null && bean.getEndDate().length() > 0) { String date = bean.getEndDate(); try { endDate = format.parse(date + " " + bean.getEndHour() + ":" + bean.getEndMin()); if (startDate != null) { if (endDate.before(startDate)) { endDate = null; } } } catch (ParseException e) { } } String ip = null; if (bean.getSourceAddress() != null && bean.getSourceAddress().length() > 0) { ip = bean.getSourceAddress(); } if (ip != null) { if (startDate != null) { if (endDate != null) { ents = errorDao.getBetween(ip, startDate, endDate); } else { ents = errorDao.getAfter(ip, startDate); } } else { if (endDate != null) { ents = errorDao.getBefore(ip, endDate); } else { ents = errorDao.getBySourceIp(ip); } } } return ents; }
From source file:org.schedulesdirect.grabber.ScheduleTask.java
protected void fetchStations(Map<String, Collection<String>> ids) { if (ids == null || ids.size() == 0) { LOG.info("No stale schedules identified; skipping schedule download!"); return;/*from w w w .ja v a 2 s. c o m*/ } DefaultJsonRequest req = factory.get(DefaultJsonRequest.Action.POST, RestNouns.SCHEDULES, clnt.getHash(), clnt.getUserAgent(), clnt.getBaseUrl()); JSONArray data = new JSONArray(); Iterator<String> idItr = ids.keySet().iterator(); while (idItr.hasNext()) { String id = idItr.next(); JSONObject o = new JSONObject(); o.put("stationID", id); Collection<String> dates = new ArrayList<>(); for (String date : ids.get(id)) dates.add(date); o.put("date", dates); data.put(o); } try { JSONArray resp = Config.get().getObjectMapper().readValue(req.submitForJson(data), JSONArray.class); for (int i = 0; i < resp.length(); ++i) { JSONObject o = resp.getJSONObject(i); if (!JsonResponseUtils.isErrorResponse(o)) { JSONArray sched = o.getJSONArray("programs"); String schedId = o.getString("stationID"); Date expiry = new Date(System.currentTimeMillis() - Grabber.MAX_AIRING_AGE); for (int j = 0; j < sched.length(); ++j) { try { JSONObject airing = sched.getJSONObject(j); Date end = AiringUtils.getEndDate(airing); String progId = airing.getString("programID"); if (!end.before(expiry)) { String md5 = airing.getString("md5"); cache.markIfDirty(progId, md5); } else LOG.debug(String.format("Expired airing discovered and ignored! [%s; %s; %s]", progId, o.getString("stationID"), end)); synchronized (ScheduleTask.class) { List<JSONObject> objs = FULL_SCHEDS.get(schedId); if (objs == null) { objs = new ArrayList<JSONObject>(); FULL_SCHEDS.put(schedId, objs); } objs.add(airing); } } catch (JSONException e) { LOG.warn(String.format("JSONException [%s]", o.optString("stationID", "unknown")), e); } } } else if (JsonResponseUtils.getErrorCode(o) == ApiResponse.SCHEDULE_QUEUED) LOG.warn(String.format( "StationID %s is queued server side and will be downloaded on next EPG update!", o.getString("stationID"))); else throw new InvalidJsonObjectException("Error received for schedule", o.toString(3)); } } catch (JSONException | JsonParseException e) { Grabber.failedTask = true; LOG.fatal("Fatal JSON error!", e); throw new RuntimeException(e); } catch (IOException e) { Grabber.failedTask = true; LOG.error("IOError receiving schedule data! Filling cache with empty schedules!", e); try { JSONArray schedIds = this.req; for (int i = 0; i < schedIds.length(); ++i) { String id = schedIds.getString(i); Path p = vfs.getPath("schedules", String.format("%s.txt", id)); if (!Files.exists(p)) { JSONObject emptySched = new JSONObject(); emptySched.put("stationID", id); emptySched.put("programs", new JSONArray()); Files.write(p, emptySched.toString(3).getBytes(ZipEpgClient.ZIP_CHARSET)); } } } catch (Exception x) { LOG.error("Unexpected error!", x); throw new RuntimeException(x); } } }
From source file:jp.terasoluna.fw.validation.ValidationUtil.java
/** * ???????????/*from ww w. j a va2 s.co m*/ * * <code>null</code> ??????? * * @param value * @param startDateStr * ???? * <code>datePattern</code>????? * <code>datePatternStrict</code>???????? * @param endDateStr * ???? * <code>datePattern</code>????? * <code>datePatternStrict</code>???????? * @param datePattern ? * @param datePatternStrict ? * @return * ?????????? * <code>true</code>? * ?????<code>false</code>? */ public static boolean isDateInRange(String value, String startDateStr, String endDateStr, String datePattern, String datePatternStrict) { // ?null?????true? if (StringUtils.isEmpty(value)) { return true; } // ?? Date result = toDate(value, datePattern, datePatternStrict); if (result == null) { return false; } if (GenericValidator.isBlankOrNull(startDateStr) && GenericValidator.isBlankOrNull(endDateStr)) { // ???????????? return true; } // ?????? if (!GenericValidator.isBlankOrNull(startDateStr)) { Date startDate = toDate(startDateStr, datePattern, datePatternStrict); if (startDate == null) { throw new IllegalArgumentException("startDate is unparseable[" + startDateStr + "]"); } if (result.before(startDate)) { return false; } } // ?????? if (!GenericValidator.isBlankOrNull(endDateStr)) { Date endDate = toDate(endDateStr, datePattern, datePatternStrict); if (endDate == null) { throw new IllegalArgumentException("endDate is unparseable[" + endDateStr + "]"); } if (result.after(endDate)) { return false; } } return true; }
From source file:com.feilong.core.date.DateUtil.java
/** * <code>date</code> ? <code>beginTimeDate</code> <code>endTimeDate</code>. * //w w w . j a va 2 s . com * <pre class="code"> * DateUtil.isInTime("2012-10-16 23:00:02", "2012-10-10 22:59:00", "2012-10-18 22:59:00") = true * </pre> * * @param date * * @param beginTimeDate * the begin time date * @param endTimeDate * the end time date * @return <code>date</code> <code>beginTimeDate</code>?, <code>date</code> <code>endTimeDate</code>?,true<br> * @throws NullPointerException * <code>date</code> null, <code>beginTimeDate</code> null <code>endTimeDate</code> null * @see Date#after(Date) * @see Date#before(Date) */ public static boolean isInTime(Date date, Date beginTimeDate, Date endTimeDate) { Validate.notNull(date, "date can't be null!"); Validate.notNull(beginTimeDate, "beginTimeDate can't be null!"); Validate.notNull(endTimeDate, "endTimeDate can't be null!"); return date.after(beginTimeDate) && date.before(endTimeDate); }