List of usage examples for org.apache.commons.lang3.time DateUtils addDays
public static Date addDays(final Date date, final int amount)
From source file:models.support.SearchCondition.java
public ExpressionList<Issue> asExpressionList() { ExpressionList<Issue> el = Issue.finder.where(); if (assigneeId != null) { if (assigneeId.equals(User.anonymous.id)) { el.isNull("assignee"); } else {/*from www . java2 s . c om*/ el.eq("assignee.user.id", assigneeId); } } if (authorId != null) { el.eq("authorId", authorId); } // TODO: access control if (mentionId != null) { User mentionUser = User.find.byId(mentionId); if (!mentionUser.isAnonymous()) { List<Long> ids = getMentioningIssueIds(mentionUser); if (ids.isEmpty()) { // No need to progress because the query matches nothing. ids.add(-1l); return el.idIn(ids); } else { el.idIn(ids); } } } if (StringUtils.isNotBlank(filter)) { Junction<Issue> junction = el.disjunction(); junction.icontains("title", filter).icontains("body", filter); List<Object> ids = Issue.finder.where().icontains("comments.contents", filter).findIds(); if (!ids.isEmpty()) { junction.idIn(ids); } junction.endJunction(); } if (commentedCheck) { el.ge("numOfComments", AbstractPosting.NUMBER_OF_ONE_MORE_COMMENTS); } State st = State.getValue(state); if (st.equals(State.OPEN) || st.equals(State.CLOSED)) { el.eq("state", st); } if (StringUtils.isNotBlank(orderBy)) { if (orderBy.equals("dueDate")) { String formulaName = orderDir.equals("asc") ? "dueDateAsc" : "dueDateDesc"; el.orderBy(formulaName + " " + orderDir); } else { el.orderBy(orderBy + " " + orderDir); } } if (dueDate != null) { el.lt("dueDate", DateUtils.addDays(dueDate, 1)); } return el; }
From source file:com.dominion.salud.pedicom.negocio.tools.PDFService.java
/** * Demonio que realiza el borrado de pdf *//*from w ww .j a v a2s .c o m*/ @Scheduled(cron = PEDICOMConstantes._TASK_PDF_DELETE) public void deletePDF() { logger.info("Comienza el borrado automatico de pdf"); File dir = new File(PEDICOMConstantes._HOME + File.separator + "reports" + File.separator); logger.debug(" Directorio de borrado en: " + dir.getPath()); Collection<File> list = FileUtils.listFiles(dir, FileFilterUtils.ageFileFilter(DateUtils.addDays(new Date(), -1), true), null); for (File fil : list) { if (!StringUtils.equalsIgnoreCase(fil.getName(), "No_encontrado.pdf")) { FileUtils.deleteQuietly(fil); } } logger.info("Borrado completado"); }
From source file:com.dominion.salud.mpr.negocio.repositories.integracion.BuzonInHisRepositoryTest.java
@Test public void findAllByAntiguedad() { logger.debug("INIT [" + getClass().getName() + ".findAllByAntiguedad()]"); try {/*from w w w .j a v a 2 s.c o m*/ buzonInHis.setFechaIn( DateUtils.addDays(new Date(), ((MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD + 1) * -1))); buzonInHisRepository.save(buzonInHis); logger.debug(" UPDATE: " + buzonInHis.toString()); buzonInHis.setFechaIn(DateUtils.addDays(new Date(), (MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD * -1))); List<BuzonInHis> listaBuzonInHis = buzonInHisRepository.findAllByAntiguedad(); if (listaBuzonInHis != null && !listaBuzonInHis.isEmpty()) { Iterator<BuzonInHis> iteradorBuzonInHis = listaBuzonInHis.iterator(); while (iteradorBuzonInHis.hasNext()) { logger.debug(" FIND_ALL_BY_ANTIGUEDAD: " + iteradorBuzonInHis.next().toString()); } } Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".findAllByAntiguedad()]"); }
From source file:com.dominion.salud.mpr.negocio.repositories.integracion.BuzonOutHisRepositoryTest.java
@Test public void findAllByAntiguedad() { logger.debug("INIT [" + getClass().getName() + ".findAllByAntiguedad()]"); try {/*from w ww. j a v a2s .c o m*/ buzonOutHis.setFechaOut( DateUtils.addDays(new Date(), ((MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD + 1) * -1))); buzonOutHisRepository.save(buzonOutHis); logger.debug(" UPDATE: " + buzonOutHis.toString()); buzonOutHis .setFechaOut(DateUtils.addDays(new Date(), (MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD * -1))); List<BuzonOutHis> listaBuzonOutHis = buzonOutHisRepository.findAllByAntiguedad(); if (listaBuzonOutHis != null && !listaBuzonOutHis.isEmpty()) { Iterator<BuzonOutHis> iteradorBuzonOutHis = listaBuzonOutHis.iterator(); while (iteradorBuzonOutHis.hasNext()) { logger.debug(" FIND_ALL_BY_ANTIGUEDAD: " + iteradorBuzonOutHis.next().toString()); } } Assert.assertTrue(true); } catch (Exception e) { Assert.fail(e.toString()); } logger.debug("END [" + getClass().getName() + ".findAllByAntiguedad()]"); }
From source file:com.omertron.themoviedbapi.methods.TmdbTVTest.java
/** * Test of getTVChanges method, of class TmdbTV. * * @throws com.omertron.themoviedbapi.MovieDbException *//*from w w w. j a va 2s . c om*/ @Test public void testGetTVChanges() throws MovieDbException { LOG.info("getTVChanges"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String startDate = sdf.format(DateUtils.addDays(new Date(), -14)); String endDate = ""; int maxCheck = 5; TmdbChanges chgs = new TmdbChanges(getApiKey(), getHttpTools()); ResultList<ChangeListItem> changeList = chgs.getChangeList(MethodBase.TV, null, null, null); LOG.info("Found {} changes to check, will check maximum of {}", changeList.getResults().size(), maxCheck); int count = 1; ResultList<ChangeKeyItem> result; for (ChangeListItem item : changeList.getResults()) { result = instance.getTVChanges(item.getId(), startDate, endDate); for (ChangeKeyItem ci : result.getResults()) { assertNotNull("Null changes", ci); } if (count++ > maxCheck) { break; } } }
From source file:gov.nih.nci.firebird.data.WorkHistoryTest.java
@Test public void testCompareTo() throws Exception { WorkHistory workHistory2 = new WorkHistory(); Date effectiveDate = new Date(); workHistory.setEffectiveDate(effectiveDate); workHistory2.setEffectiveDate(DateUtils.addDays(effectiveDate, 1)); assertTrue(workHistory.compareTo(workHistory2) < 0); }
From source file:com.netsteadfast.greenstep.bsc.action.HistoryItemScoreReportAction.java
public String getStartDate() { Date endDate = DateUtils.addDays(new Date(), -30); return DateFormatUtils.format(endDate, "yyyy/MM/dd"); }
From source file:com.progym.custom.fragments.CalloriesProgressMonthlyLineFragment.java
public void setLineData3(final Date date, final boolean isLeftIn) { final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(), getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data), true);//from w w w . j av a 2 s . com ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { int yMaxAxisValue = 0; try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { rlRootGraphLayout.removeView(mChartView); } }); } catch (Exception edsx) { edsx.printStackTrace(); } date.setDate(1); DATE = date; // Get amount of days in a month to find out average int daysInMonth = Utils.getDaysInMonth(date.getMonth(), Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY))); // set First day of the month as first month int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }; // Creating an XYSeries for Consumed water XYSeries callories = new XYSeries("Callories"); List<Ingridient> list; Date dt = date; // ** // Adding data to Income and Expense Series for (int i = 1; i <= daysInMonth; i++) { // get all water records consumed per this month list = DataBaseUtils.getAllFoodConsumedInMonth( Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM_DD)); // init "average" data int totalCallories = 0; for (Ingridient ingridient : list) { totalCallories += ingridient.kkal; } callories.add(i, totalCallories); dt = DateUtils.addDays(dt, 1); yMaxAxisValue = Math.max(yMaxAxisValue, totalCallories); } // Creating a dataset to hold each series final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); // Adding Income Series to the dataset dataset.addSeries(callories); // Creating XYSeriesRenderer to customize protein series XYSeriesRenderer calloriesRenderer = new XYSeriesRenderer(); calloriesRenderer.setColor(Color.rgb(220, 255, 110)); calloriesRenderer.setFillPoints(true); calloriesRenderer.setLineWidth(3); calloriesRenderer.setDisplayChartValues(true); // Creating a XYMultipleSeriesRenderer to customize the whole chart final XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer(); // multiRenderer.setXLabels(0); for (int i = 0; i < x.length; i++) { multiRenderer.addXTextLabel(i, String.valueOf(x[i])); } // Adding incomeRenderer and expenseRenderer to multipleRenderer // Note: The order of adding dataseries to dataset and renderers to multipleRenderer // should be same multiRenderer.setChartTitle(String.format("Callories statistic")); multiRenderer.setXTitle(Utils.getSpecificDateValue(DATE, "MMM") + " of " + Utils.formatDate(DATE, DataBaseUtils.DATE_PATTERN_YYYY)); multiRenderer.setYTitle(getActivity().getResources().getString(R.string.callories_consumption)); multiRenderer.setAxesColor(Color.WHITE); multiRenderer.setShowLegend(true); multiRenderer.addSeriesRenderer(calloriesRenderer); multiRenderer.setShowGrid(true); multiRenderer.setClickEnabled(true); multiRenderer.setXLabelsAngle(20); multiRenderer.setYAxisMax(yMaxAxisValue + 200); multiRenderer.setXLabelsColor(Color.WHITE); multiRenderer.setZoomButtonsVisible(false); // configure visible area multiRenderer.setXAxisMax(31); multiRenderer.setXAxisMin(1); multiRenderer.setAxisTitleTextSize(15); multiRenderer.setZoomEnabled(true); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mChartView = ChartFactory.getLineChartView(getActivity(), dataset, multiRenderer); rlRootGraphLayout.addView(mChartView, 0); if (isLeftIn) { rightIn.setDuration(1000); mChartView.startAnimation(rightIn); } else { leftIn.setDuration(1000); mChartView.startAnimation(leftIn); } } }); } catch (Exception e) { e.printStackTrace(); } ringProgressDialog.dismiss(); } }).start(); }
From source file:com.silverpeas.gallery.control.ejb.GalleryBmEJBTest.java
@Test public void getSocialInformationListOfMyContacts() { Date beginDate = DateUtils.addDays(CREATE_DATE, +1); Date endDate = DateUtils.addDays(CREATE_DATE, +2); List<SocialInformation> socialInformationList = galleryBmEJB.getSocialInformationListOfMyContacts( Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()), Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate)); assertThat(socialInformationList, hasSize(0)); beginDate = DateUtils.addDays(CREATE_DATE, 0); endDate = DateUtils.addDays(CREATE_DATE, +2); socialInformationList = galleryBmEJB.getSocialInformationListOfMyContacts( Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()), Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate)); assertThat(socialInformationList, hasSize(4)); beginDate = DateUtils.addDays(LAST_UPDATE_DATE, -2); endDate = DateUtils.addDays(LAST_UPDATE_DATE, +2); socialInformationList = galleryBmEJB.getSocialInformationListOfMyContacts( Arrays.asList(writerUser.getId(), adminAccessUser.getId(), publisherUser.getId()), Arrays.asList(INSTANCE_A, "otherInstanceId"), Period.from(beginDate, endDate)); assertThat(socialInformationList, hasSize(7)); }
From source file:com.netsteadfast.greenstep.bsc.service.impl.MonitorItemScoreServiceImpl.java
@Override public Map<String, List<MonitorItemScoreVO>> getHistoryDataList(String itemType, String frequency, String dateVal, String orgId, String empId, int daysBeforeRange) throws ServiceException, Exception { if (StringUtils.isBlank(itemType) || StringUtils.isBlank(frequency) || StringUtils.isBlank(dateVal)) { throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK)); }// w w w . j a v a2 s .c o m if (!SimpleUtils.isDate(dateVal)) { throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_INCORRECT)); } if (daysBeforeRange > MAX_DAYS_BEFORE_RANGE || daysBeforeRange < 0) { throw new ServiceException("daysBeforeRange error!"); } Date endDate = DateUtils.parseDate(dateVal, new String[] { "yyyyMMdd" }); Date startDate = DateUtils.addDays(endDate, (daysBeforeRange * -1)); String startDateStr = DateFormatUtils.format(startDate, "yyyyMMdd"); Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("itemType", itemType); paramMap.put("frequency", frequency); paramMap.put("orgId", orgId); paramMap.put("empId", empId); Map<String, CustomeOperational> customeMap = new HashMap<String, CustomeOperational>(); CustomeOperational op1 = new CustomeOperational(); op1.setField("dateVal"); op1.setOp(">="); op1.setValue(startDateStr); CustomeOperational op2 = new CustomeOperational(); op2.setField("dateVal"); op2.setOp("<="); op2.setValue(dateVal); customeMap.put("op1", op1); customeMap.put("op2", op2); List<BbMonitorItemScore> searchList = this.findListByParams2(paramMap, customeMap); if (null == searchList || searchList.size() < 1) { return null; } Map<String, List<MonitorItemScoreVO>> dataMap = new HashMap<String, List<MonitorItemScoreVO>>(); List<String> idKeyList = new ArrayList<String>(); for (BbMonitorItemScore data : searchList) { if (idKeyList.contains(data.getItemId())) { continue; } idKeyList.add(data.getItemId()); dataMap.put(data.getItemId(), new LinkedList<MonitorItemScoreVO>()); } for (int i = 0; i <= daysBeforeRange; i++) { Date currentDate = DateUtils.addDays(startDate, i); String currentDateStr = DateFormatUtils.format(currentDate, "yyyyMMdd"); for (String id : idKeyList) { MonitorItemScoreVO scoreData = new MonitorItemScoreVO(); scoreData.setItemType(itemType); scoreData.setItemId(id); scoreData.setFrequency(frequency); scoreData.setOrgId(orgId); scoreData.setEmpId(empId); scoreData.setDateVal(currentDateStr); scoreData.setScore("0"); // ?, ?"0" for (BbMonitorItemScore data : searchList) { if (data.getItemId().equals(id) && data.getDateVal().equals(currentDateStr)) { scoreData.setScore(data.getScore()); } } dataMap.get(id).add(scoreData); } } return dataMap; }