List of usage examples for java.util Date before
public boolean before(Date when)
From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java
private List<Date> findLessThanNow(Set<Date> keySet, Date now) { List<Date> min = new ArrayList(); for (Date date : keySet) { if (date.before(now)) { min.add(date);//from ww w. j a va 2s . c o m } } return min; }
From source file:com.gitblit.wicket.pages.BasePage.java
/** * Sets the last-modified header field and the expires field. * * @param when/* w w w .j av a 2 s . com*/ */ protected final void setLastModified(Date when) { if (when == null) { return; } if (when.before(app().getBootDate())) { // last-modified can not be before the Gitblit boot date // this helps ensure that pages are properly refreshed after a // server config change when = app().getBootDate(); } int expires = app().settings().getInteger(Keys.web.pageCacheExpires, 0); WebResponse response = (WebResponse) getResponse(); response.setLastModifiedTime(Time.valueOf(when)); response.setDateHeader("Expires", System.currentTimeMillis() + Duration.minutes(expires).getMilliseconds()); }
From source file:com.gsma.mobileconnect.impl.DiscoveryImpl.java
/** * Determine the time-to-live for a discovery response. * <p>/*w w w .ja va2 s . c om*/ * Ensure the ttl is between a minimum and maximum value. * * @param ttlTime The ttl value from the discovery result. * @return The ttl to use. */ Date determineTtl(Long ttlTime) { Long now = new Date().getTime(); Date min = new Date(now + Constants.MINIMUM_TTL_MS); Date max = new Date(now + Constants.MAXIMUM_TTL_MS); if (null == ttlTime) { return min; } Date currentTtl = new Date(ttlTime); if (currentTtl.before(min)) { return min; } if (currentTtl.after(max)) { return max; } return currentTtl; }
From source file:com.enioka.jqm.tools.LibraryCache.java
/** * Returns true if the libraries should be loaded in cache. Two cases: never loaded and should be reloaded (jar is more recent than * cache)/*from www .j a v a 2 s.c om*/ */ private boolean shouldLoad(Node node, JobDef jd) { if (!cache.containsKey(jd.getApplicationName())) { return true; } // If here: cache exists. JobDefLibrary libs = cache.get(jd.getApplicationName()); // Is cache stale? Date lastLoaded = libs.loadTime; File jarFile = new File(FilenameUtils.concat(new File(node.getRepo()).getAbsolutePath(), jd.getJarPath())); File jarDir = jarFile.getParentFile(); File libDir = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "lib")); if (lastLoaded.before(new Date(jarFile.lastModified())) || lastLoaded.before(new Date(jarDir.lastModified())) || lastLoaded.before(new Date(libDir.lastModified()))) { jqmlogger.info("The cache for application " + jd.getApplicationName() + " will be reloaded"); return true; } // If here, the cache is OK return false; }
From source file:mekhq.Utilities.java
/** * Calculates the number of days between start and end dates, taking * into consideration leap years, year boundaries etc. * * @param start the start date/*w ww.j a v a 2 s . c o m*/ * @param end the end date, must be later than the start date * @return the number of days between the start and end dates */ public static long countDaysBetween(Date start, Date end) { if (end.before(start)) { throw new IllegalArgumentException("The end date must be later than the start date"); } //reset all hours mins and secs to zero on start date Calendar startCal = GregorianCalendar.getInstance(); startCal.setTime(start); startCal.set(Calendar.HOUR_OF_DAY, 0); startCal.set(Calendar.MINUTE, 0); startCal.set(Calendar.SECOND, 0); long startTime = startCal.getTimeInMillis(); //reset all hours mins and secs to zero on end date Calendar endCal = GregorianCalendar.getInstance(); endCal.setTime(end); endCal.set(Calendar.HOUR_OF_DAY, 0); endCal.set(Calendar.MINUTE, 0); endCal.set(Calendar.SECOND, 0); long endTime = endCal.getTimeInMillis(); return (endTime - startTime) / MILLISECONDS_IN_DAY; }
From source file:org.jasig.schedassist.portlet.VisibleScheduleTag.java
@Override public int doStartTagInternal() { RenderRequest renderRequest = (RenderRequest) pageContext.getRequest().getAttribute(PORTLET_REQUEST); RenderResponse renderResponse = (RenderResponse) pageContext.getRequest().getAttribute(PORTLET_RESPONSE); final Date scheduleStart = visibleSchedule.getScheduleStart(); if (null == scheduleStart) { // the visibleSchedule is empty, short circuit try {//from w w w. j a va2s . co m StringBuilder noappointments = new StringBuilder(); noappointments.append("<span class=\"none-available\">"); noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null)); noappointments.append("</span>"); pageContext.getOut().write(noappointments.toString()); } catch (IOException e) { LOG.error("IOException occurred in doStartTag", e); } // SKIP_BODY means don't print any content from body of tag return SKIP_BODY; } LOG.debug("scheduleStart: " + scheduleStart); SortedMap<Date, List<AvailableBlock>> dailySchedules = new TreeMap<Date, List<AvailableBlock>>(); Date index = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE); Date scheduleEnd = visibleSchedule.getScheduleEnd(); while (index.before(scheduleEnd)) { dailySchedules.put(index, new ArrayList<AvailableBlock>()); index = DateUtils.addDays(index, 1); } final Date lastMapKey = dailySchedules.lastKey(); LOG.debug("visibleSchedule spans " + dailySchedules.keySet().size() + " days"); try { SortedMap<AvailableBlock, AvailableStatus> scheduleBlockMap = visibleSchedule.getBlockMap(); int numberOfEventsToDisplay = 0; for (AvailableBlock block : scheduleBlockMap.keySet()) { Date eventStartDate = block.getStartTime(); LOG.debug("event start date: " + eventStartDate); Date mapKey = DateUtils.truncate(eventStartDate, java.util.Calendar.DATE); if (CommonDateOperations.equalsOrAfter(eventStartDate, scheduleStart) && dailySchedules.containsKey(mapKey)) { dailySchedules.get(mapKey).add(block); numberOfEventsToDisplay++; } } LOG.debug("number of events to display: " + numberOfEventsToDisplay); if (numberOfEventsToDisplay == 0) { // no available times in this range! StringBuilder noappointments = new StringBuilder(); noappointments.append("<span class=\"none-available\">"); noappointments.append(getMessageSource().getMessage("no.available.appointments", null, null)); noappointments.append("</span>"); pageContext.getOut().write(noappointments.toString()); } else { int weekNumber = 1; Date currentWeekStart = DateUtils.truncate(scheduleStart, java.util.Calendar.DATE); Date currentWeekFinish = DateUtils.addDays(currentWeekStart, CommonDateOperations.numberOfDaysUntilSunday(currentWeekStart)); currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1); boolean renderAnotherWeek = true; while (renderAnotherWeek) { if (LOG.isDebugEnabled()) { LOG.debug("will render another week using currentWeekStart " + currentWeekStart + " and currentWeekFinish " + currentWeekFinish); } SortedMap<Date, List<AvailableBlock>> subMap = dailySchedules.subMap(currentWeekStart, currentWeekFinish); renderWeek(pageContext.getOut(), weekNumber++, subMap, scheduleBlockMap, renderRequest, renderResponse); currentWeekStart = DateUtils.addMinutes(currentWeekFinish, 1); currentWeekFinish = DateUtils.addDays(currentWeekStart, 7); currentWeekFinish = DateUtils.addMinutes(currentWeekFinish, -1); if (LOG.isDebugEnabled()) { LOG.debug("recalculated currentWeekStart " + currentWeekStart + ", currentWeekFinish " + currentWeekFinish); } if (currentWeekStart.after(lastMapKey)) { renderAnotherWeek = false; LOG.debug("will not render another week"); } } } } catch (IOException e) { LOG.error("IOException occurred in doStartTag", e); } // SKIP_BODY means don't print any content from body of tag return SKIP_BODY; }
From source file:com.digitalpebble.stormcrawler.bolt.FeedParserBolt.java
private List<Outlink> parseFeed(String url, byte[] content, Metadata parentMetadata) throws MalformedURLException { List<Outlink> links = new ArrayList<>(); SyndFeed feed = null;//from w w w. ja v a 2s .co m try (ByteArrayInputStream is = new ByteArrayInputStream(content)) { SyndFeedInput input = new SyndFeedInput(); feed = input.build(new InputSource(is)); } catch (Exception e) { LOG.error("Exception parsing feed from DOM {}", url); return links; } URL sURL = new URL(url); List<SyndEntry> entries = feed.getEntries(); for (SyndEntry entry : entries) { String targetURL = entry.getLink(); // build an absolute URL try { targetURL = URLUtil.resolveURL(sURL, targetURL).toExternalForm(); } catch (MalformedURLException e) { LOG.debug("MalformedURLException on {}", targetURL); continue; } targetURL = urlFilters.filter(sURL, parentMetadata, targetURL); if (StringUtils.isBlank(targetURL)) continue; Outlink newLink = new Outlink(targetURL); Metadata targetMD = metadataTransfer.getMetaForOutlink(targetURL, url, parentMetadata); newLink.setMetadata(targetMD); String title = entry.getTitle(); if (StringUtils.isNotBlank(title)) { targetMD.setValue("feed.title", title.trim()); } Date publishedDate = entry.getPublishedDate(); if (publishedDate != null) { // filter based on the published date if (filterHoursSincePub != -1) { Calendar rightNow = Calendar.getInstance(); rightNow.add(Calendar.HOUR, -filterHoursSincePub); if (publishedDate.before(rightNow.getTime())) { LOG.info("{} has a published date {} which is more than {} hours old", targetURL, publishedDate.toString(), filterHoursSincePub); continue; } } targetMD.setValue("feed.publishedDate", publishedDate.toString()); } SyndContent description = entry.getDescription(); if (description != null && StringUtils.isNotBlank(description.getValue())) { targetMD.setValue("feed.description", description.getValue()); } links.add(newLink); } return links; }
From source file:com.inkubator.hrm.service.impl.JadwalKerjaMassExceptionMessagesListener.java
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, timeout = 50, rollbackFor = Exception.class) public void onMessage(Message message) { try {//from w w w . ja v a 2s .c om TextMessage textMessage = (TextMessage) message; JSONObject jSONObject = new JSONObject(textMessage.getText()); long workingGroupId = Long.parseLong(jSONObject.getString("groupWorkingId")); String listEmp = jSONObject.getString("listEmpId"); Date createOn = new SimpleDateFormat("dd-MM-yyyy hh:mm").parse(jSONObject.getString("createDate")); String createBy = jSONObject.getString("createBy"); String startDateString = jSONObject.getString("startDate"); String endDateString = jSONObject.getString("endDate"); Date startProposeDate = new SimpleDateFormat("dd-MM-yyyy hh:mm") .parse(jSONObject.getString("startDate")); Gson gson = new GsonBuilder().create(); // List<TempJadwalKaryawan> dataToDelete = new ArrayList<>(); TypeToken<List<Long>> token = new TypeToken<List<Long>>() { }; List<Long> dataEmpId = gson.fromJson(listEmp, token.getType()); //Date now = new Date(); WtGroupWorking groupWorking = wtGroupWorkingDao.getEntiyByPK(workingGroupId); Date startDate = groupWorking.getBeginTime();//tidak ditempatkan di dalam loop karena untuk groupworking yang sama Date endDate = groupWorking.getEndTime(); int numberOfDay = DateTimeUtil.getTotalDayDifference(startDate, endDate); int totalDateDif = DateTimeUtil.getTotalDayDifference(startDate, startProposeDate) + 1; int num = numberOfDay + 1; int hasilBagi = (totalDateDif) / (num); Date tanggalAkhirJadwal = new SimpleDateFormat("dd-MM-yyyy hh:mm") .parse(jSONObject.getString("endDate")); // String dayBegin = new SimpleDateFormat("EEEE").format(endDate); // String dayNow = new SimpleDateFormat("EEEE").format(now); Date beginScheduleDate; if (new SimpleDateFormat("ddMMyyyy").format(tanggalAkhirJadwal) .equals(new SimpleDateFormat("ddMMyyyy").format(new Date()))) { beginScheduleDate = DateTimeUtil.getDateFrom(startDate, (hasilBagi * num) - num, CommonUtilConstant.DATE_FORMAT_DAY); } else { beginScheduleDate = DateTimeUtil.getDateFrom(startDate, (hasilBagi * num), CommonUtilConstant.DATE_FORMAT_DAY); } List<TempJadwalKaryawan> dataToSave = new ArrayList<>(); TempJadwalKaryawan jadwalKaryawan; for (Long id : dataEmpId) { // dataToDelete.addAll(tempJadwalKaryawanDao.getAllByEmpId(id)); for bussiner process Sake so must be close List<WtScheduleShift> dataScheduleShift = new ArrayList<>(groupWorking.getWtScheduleShifts()); // Collections.sort(dataScheduleShift, shortByDate1); int totaldayPropsot = DateTimeUtil.getTotalDayDifference(startProposeDate, tanggalAkhirJadwal); int loop = totaldayPropsot / dataScheduleShift.size(); List<WtScheduleShift> sortedDataScheduleShift = Lambda.sort(dataScheduleShift, Lambda.on(WtScheduleShift.class).getScheduleDate()); int i = 0; // for (int a = 0; a < loop; a++) { for (WtScheduleShift wtScheduleShift : sortedDataScheduleShift) { String onlyDate = new SimpleDateFormat("yyyy-MM-dd").format( DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY)); Date olnyDate = new SimpleDateFormat("yyyy-MM-dd").parse(onlyDate); jadwalKaryawan = tempJadwalKaryawanDao.getByEmpId(id, olnyDate); if (jadwalKaryawan != null) { jadwalKaryawan.setUpdatedBy(createBy); jadwalKaryawan.setUpdatedOn(new Date()); // jadwalKaryawan = tempJadwalKaryawanDao.getByEmpId(empData.getId(), olnyDate); } else { jadwalKaryawan = new TempJadwalKaryawan(); jadwalKaryawan.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(12))); jadwalKaryawan.setEmpData(empDataDao.getEntiyByPK(id)); jadwalKaryawan.setTanggalWaktuKerja( DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY)); jadwalKaryawan.setCreatedBy(createBy); jadwalKaryawan.setCreatedOn(createOn); } // TempJadwalKaryawan jadwalKaryawan = new TempJadwalKaryawan(); // jadwalKaryawan.setEmpData(empDataDao.getEntiyByPK(id)); // jadwalKaryawan.setTanggalWaktuKerja(DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY)); // jadwalKaryawan.setWtWorkingHour(wtScheduleShift.getWtWorkingHour()); WtHoliday holiday = wtHolidayDao.getWtHolidayByDate(jadwalKaryawan.getTanggalWaktuKerja()); if (holiday != null && groupWorking.getTypeSequeace().equals(HRMConstant.NORMAL_SCHEDULE)) { jadwalKaryawan.setWtWorkingHour(wtWorkingHourDao.getByCode("OFF")); } else { jadwalKaryawan.setWtWorkingHour(wtScheduleShift.getWtWorkingHour()); } // WtHoliday holiday = wtHolidayDao.getWtHolidayByDate(jadwalKaryawan.getTanggalWaktuKerja()); // if (holiday != null || wtScheduleShift.getWtWorkingHour().getCode().equalsIgnoreCase("OFF")) { // jadwalKaryawan.setAttendanceStatus(attendanceStatusDao.getByCode("OFF")); // } else { // jadwalKaryawan.setAttendanceStatus(attendanceStatusDao.getByCode("HD1")); // } jadwalKaryawan.setIsCollectiveLeave(Boolean.FALSE); Date jadwal = jadwalKaryawan.getTanggalWaktuKerja(); if (jadwal.equals(startProposeDate) || jadwal.equals(tanggalAkhirJadwal)) { dataToSave.add(jadwalKaryawan); } if ((jadwal.after(startProposeDate) && jadwal.before(tanggalAkhirJadwal))) { dataToSave.add(jadwalKaryawan); } i++; } // } } // tempJadwalKaryawanDao.deleteBacth(dataToDelete); tempJadwalKaryawanDao.saveBatch(dataToSave); //sending email process // this.sendingEmailJadwalKaryawan(dataToSave, jSONObject.getString("locale")); } catch (Exception ex) { LOGGER.error("Error", ex); } }
From source file:net.sf.statcvs.output.xml.chart.ModuleActivityChart.java
private ContourDataset createDataset() { List dirs = content.getDirectories(); List dateList = new ArrayList(); Date firstDate = content.getFirstDate(); Date lastDate = content.getLastDate(); Calendar cal = new GregorianCalendar(); cal.setTime(firstDate);/* w w w . ja v a2s . c om*/ while (cal.getTime().before(lastDate)) { dateList.add(cal.getTime()); cal.add(Calendar.DATE, 1); } dateList.add(lastDate); Double[][] values = new Double[dateList.size()][dirs.size()]; for (int i = 0; i < dateList.size(); i++) { Iterator dirsIt = dirs.iterator(); IntegerMap changesMap = new IntegerMap(); while (dirsIt.hasNext()) { Directory dir = (Directory) dirsIt.next(); RevisionIterator revIt = new RevisionSortIterator(dir.getRevisionIterator()); while (revIt.hasNext()) { CvsRevision rev = revIt.next(); Date revDate = rev.getDate(); Date currDate = (Date) dateList.get(i); Date nextDate = null; if (i < dateList.size() - 1) { nextDate = (Date) dateList.get(i + 1); } if (revDate.equals(currDate) || (revDate.after(currDate) && revDate.before(nextDate))) { changesMap.inc(dir); } } } Iterator cIt = changesMap.iteratorSortedByKey(); while (cIt.hasNext()) { Directory dir = (Directory) cIt.next(); int dirIndex = dirs.indexOf(dir); //values[i][dirIndex] = new Double(changesMap.getPercent(dir)); values[i][dirIndex] = new Double(changesMap.getPercentOfMaximum(dir)); } } int numValues = dateList.size() * dirs.size(); Date[] oDateX = new Date[numValues]; Double[] oDoubleY = new Double[numValues]; Double[] oDoubleZ = new Double[numValues]; for (int x = 0; x < dateList.size(); x++) { for (int y = 0; y < dirs.size(); y++) { int index = (x * dirs.size()) + y; oDateX[index] = (Date) dateList.get(x); oDoubleY[index] = new Double(y); if ((values[x][y] != null) && ((values[x][y].isNaN()) || (values[x][y].equals(new Double(0))))) { values[x][y] = null; } oDoubleZ[index] = values[x][y]; } } oDoubleZ[0] = new Double(0.0); return new DefaultContourDataset(getTitle(), oDateX, oDoubleY, oDoubleZ); }
From source file:org.jasig.schedassist.impl.SchedulingAssistantServiceImpl.java
@Override public VisibleSchedule getVisibleSchedule(final IScheduleVisitor visitor, final IScheduleOwner owner, final Date start, final Date end) { Validate.notNull(start, "start parameter cannot be null"); Validate.notNull(end, "start parameter cannot be null"); Date[] windowBoundaries = calculateOwnerWindowBounds(owner); Date localStart = start;//from w w w . j a v a2 s . c o m if (start.before(windowBoundaries[0]) || start.after(windowBoundaries[1])) { if (LOG.isDebugEnabled()) { LOG.debug("ignoring submitted start for getVisibleSchedule: " + start + " (using windowBoundary of " + windowBoundaries[0] + ")"); } localStart = windowBoundaries[0]; } Date localEnd = end; if (end.after(windowBoundaries[1])) { if (LOG.isDebugEnabled()) { LOG.debug("ignoring submitted end for getVisibleSchedule: " + end + " (using windowBoundary of " + windowBoundaries[1] + ")"); } localEnd = windowBoundaries[1]; } Calendar calendar = calendarDao.getCalendar(owner.getCalendarAccount(), localStart, localEnd); AvailableSchedule schedule = availableScheduleDao.retrieve(owner); VisibleSchedule result = this.visibleScheduleBuilder.calculateVisibleSchedule(localStart, localEnd, calendar, schedule, owner, visitor); return result; }