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:com.nridge.core.app.mgr.ServiceTimer.java
private Date getNextTS(String aFieldName, Date aTS) { String timeString = getAppString(aFieldName); if (StringUtils.isNotEmpty(timeString)) { if (StringUtils.endsWithIgnoreCase(timeString, "m")) { String minuteString = StringUtils.stripEnd(timeString, "m"); if ((StringUtils.isNotEmpty(minuteString)) && (StringUtils.isNumeric(minuteString))) { int minuteAmount = Integer.parseInt(minuteString); return DateUtils.addMinutes(aTS, minuteAmount); }/*from www . j av a2s .com*/ } else if (StringUtils.endsWithIgnoreCase(timeString, "h")) { String hourString = StringUtils.stripEnd(timeString, "h"); if ((StringUtils.isNotEmpty(hourString)) && (StringUtils.isNumeric(hourString))) { int hourAmount = Integer.parseInt(hourString); return DateUtils.addHours(aTS, hourAmount); } } else // we assume days { String dayString = StringUtils.stripEnd(timeString, "d"); if ((StringUtils.isNotEmpty(dayString)) && (StringUtils.isNumeric(dayString))) { int dayAmount = Integer.parseInt(dayString); return DateUtils.addDays(aTS, dayAmount); } } } // Push 1 hour ahead to avoid triggering a match with TS return DateUtils.addHours(new Date(), 1); }
From source file:eu.ggnet.dwoss.report.assist.gen.ReportLineGenerator.java
public ReportLine makeReportLine() { ReportLine reportLine = new ReportLine(); Date pastFiveYears = DateUtils.setYears(new Date(), 2009); reportLine.setName("ReportLine-" + getRandomInt()); reportLine.setDescription("desription-" + getRandomInt()); reportLine.setDossierId(getRandomLong()); reportLine.setDocumentIdentifier("dossierIdentifier-" + getRandomInt()); reportLine.setDocumentId(getRandomLong()); reportLine.setDocumentIdentifier("documentIdentifier-" + getRandomInt()); reportLine.setPositionType(PositionType.values()[R.nextInt(PositionType.values().length)]); reportLine.setDocumentType(DocumentType.values()[R.nextInt(DocumentType.values().length)]); reportLine.setCustomerId(getRandomLong()); reportLine.setAmount(getRandomLong()); double tax = GlobalConfig.TAX; double price = Math.abs(R.nextDouble() * R.nextInt(1500)); reportLine.setManufacturerCostPrice(price + 15); reportLine.setAfterTaxPrice(price + (price * tax)); reportLine.setPrice(price);// www .j a v a 2 s . c o m reportLine.setTax(tax); reportLine.setBookingAccount(getRandomInt()); GeneratedAddress makeAddress = new NameGenerator().makeAddress(); Name makeName = new NameGenerator().makeName(); String invoiceAdress = makeName.getFirst() + " " + makeName.getLast() + ", " + makeAddress.getStreet() + " " + makeAddress.getNumber() + ", " + makeAddress.getPostalCode() + " " + makeAddress.getTown(); reportLine.setInvoiceAddress(invoiceAdress); reportLine.setRefurbishId("" + R.nextInt(100000)); reportLine.setUniqueUnitId(getRandomLong()); reportLine.setSerial("serial" + getRandomInt()); reportLine.setProductId(getRandomLong()); reportLine.setPartNo("partNo" + getRandomInt()); List<TradeName> names = new ArrayList<>(); names.addAll(Arrays.asList(TradeName.ACER, TradeName.APPLE, TradeName.DELL, TradeName.HP)); reportLine.setContractor(names.get(R.nextInt(names.size()))); reportLine.setProductBrand(names.get(R.nextInt(names.size()))); reportLine.setMfgDate(DateUtils.addDays(pastFiveYears, R.nextInt(2000))); reportLine.setReportingDate(DateUtils.addDays(reportLine.getMfgDate(), R.nextInt(400))); return reportLine; }
From source file:gov.nih.nci.firebird.service.task.CtepInvestigatorTasksGeneratorTest.java
@Test public void testGenerateTasks_RegistrationRenewal_InsideNotificationWindow() throws Exception { AnnualRegistration registration = createAndAddRegistration(APPROVED); registration.setApprovalAcknowledgedByInvestigator(true); registration/*from w w w . j a v a 2 s .c o m*/ .setDueDate(DateUtils.addDays(new Date(), DAYS_BEFORE_DUE_DATE_TO_SEND_SECOND_NOTIFICATION - 1)); List<Task> tasks = generator.generateTasks(investigator); checkForOnlyTask(tasks, INVESTIGATOR_REGISTRATION_RENEWAL_TASK_TITLE); }
From source file:com.floreantpos.license.FiveStarPOSLicenseManager.java
/** * Creates a new template file./*from w ww.j a v a2 s . c om*/ * * @param templateFile * @throws IOException */ private final void createTemplateFile(File templateFile) throws IOException { OutputStream output = new FileOutputStream(templateFile); Properties properties = new OrderedProperties(); properties.put(License.LICENSED_TO, "************"); properties.put(License.PURCHASE_ID, UUID.randomUUID().toString()); properties.put(License.PURCHASE_DATE, License.DATE_FORMAT.format(new Date())); properties.put(License.MACHINE_KEY, "************"); properties.put(License.BACK_OFFICE, "false"); properties.put(License.KITCHEN_DISPLAY, "false"); properties.put(License.EXPIRATION_DATE, License.DATE_FORMAT.format(DateUtils.addDays(new Date(), 30))); properties.store(output, "License template file"); output.close(); }
From source file:eu.ggnet.dwoss.report.assist.ReportUtil.java
/** * Removes all Lines, that only represent active Info (open Complaints). * <ol>/*from w w w . j a v a 2 s .com*/ * <li>Sammle alle only Invoice Positions raus Report</li> * <li>Sammle alle Repayment Positions raus Report</li> * <li>Sammle alle Complaint Positionen die mit den Repayment Positionen zusammenhngen raus Report</li> * <li>Sammle alle Compleints die DISCHARDED sind Report</li> * <li>Alles was brig ist, sollten (offene) Complaints sein Active Info</li> * </ol> * <p> * It's not allowed to have a null value in the collection. * <p> * @param allLines all lines. * @param reportType the report type * @return */ public static PrepareReportPartition partition(Collection<ReportLine> allLines, TradeName reportType) { L.debug("filter {}", allLines); NavigableSet<ReportLine> reportAble = new TreeSet<>(); for (ReportLine line : allLines) { L.debug("filter processing {}", line.toSimple()); if (!(line.getDocumentType() == DocumentType.ANNULATION_INVOICE || line.getDocumentType() == DocumentType.CREDIT_MEMO || line.getDocumentType() == DocumentType.CAPITAL_ASSET || (line.getDocumentType() == DocumentType.COMPLAINT && line.getWorkflowStatus() == WorkflowStatus.DISCHARGED) || (line.getDocumentType() == DocumentType.INVOICE && line.hasNoRepayments()) && line.hasNoOpenComplaints())) continue; L.debug("filter processing, add to reportAble {}", line.toSimple()); reportAble.add(line); Date tomorrow = DateUtils.addDays(line.getReportingDate(), 1); for (ReportLine ref : line.getRefrences()) { if (ref.getDocumentType() == DocumentType.COMPLAINT && !ref.isInReport(reportType)) { L.debug("filter processing referencing complaints, add to reportAble {}", ref.toSimple()); reportAble.add(ref); } else if (ref.getDocumentType() == DocumentType.INVOICE && !ref.isInReport(reportType) && ref.getReportingDate().before(tomorrow)) { L.debug("filter processing referencing invoices, add to reportAble {}", ref.toSimple()); reportAble.add(ref); } } } NavigableSet<ReportLine> activeInfo = new TreeSet<>(allLines); activeInfo.removeAll(reportAble); return new PrepareReportPartition(reportAble, activeInfo); }
From source file:com.progym.custom.fragments.FoodProgressMonthlyLineFragment.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);/* w w w . j av a2s . c o m*/ ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { int yMaxAxisValue = 0; getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { rlRootGraphLayout.removeView(graphView); } 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 protein = new XYSeries("Protein"); XYSeries fat = new XYSeries("Fat"); XYSeries carbs = new XYSeries("Carbs"); 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 double totalProtein = 0, totalFat = 0, totalCarbs = 0; if (null != list) { for (Ingridient ingridient : list) { totalProtein += ingridient.protein; totalFat += ingridient.fat; totalCarbs += ingridient.carbohydrates; } } protein.add(i, (double) Math.round(totalProtein * 100) / 100); fat.add(i, (double) Math.round(totalFat * 100) / 100); carbs.add(i, (double) Math.round(totalCarbs * 100) / 100); // calories.add(i, totalCallories); dt = DateUtils.addDays(dt, 1); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalProtein); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalFat); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalCarbs); } // Creating a dataset to hold each series final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); // Adding Income Series to the dataset dataset.addSeries(protein); dataset.addSeries(carbs); dataset.addSeries(fat); // Creating XYSeriesRenderer to customize protein series XYSeriesRenderer proteinRenderer = new XYSeriesRenderer(); proteinRenderer.setColor(Color.rgb(50, 255, 50)); proteinRenderer.setFillPoints(true); proteinRenderer.setLineWidth(3); proteinRenderer.setDisplayChartValues(true); // Creating XYSeriesRenderer to customize protein series XYSeriesRenderer fatRenderer = new XYSeriesRenderer(); fatRenderer.setColor(Color.rgb(123, 111, 00)); fatRenderer.setFillPoints(true); fatRenderer.setLineWidth(3); fatRenderer.setDisplayChartValues(true); // Creating XYSeriesRenderer to customize protein series XYSeriesRenderer carbsRenderer = new XYSeriesRenderer(); carbsRenderer.setColor(Color.rgb(222, 13, 11)); carbsRenderer.setFillPoints(true); carbsRenderer.setLineWidth(3); carbsRenderer.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("Protein/Carbs/Fat statistic ")); multiRenderer.setXTitle(Utils.getSpecificDateValue(DATE, "MMM") + " of " + Utils.formatDate(DATE, DataBaseUtils.DATE_PATTERN_YYYY)); multiRenderer.setYTitle("Amount (g) "); multiRenderer.setAxesColor(Color.WHITE); multiRenderer.setShowLegend(true); multiRenderer.addSeriesRenderer(proteinRenderer); multiRenderer.addSeriesRenderer(carbsRenderer); multiRenderer.addSeriesRenderer(fatRenderer); multiRenderer.setShowGrid(true); multiRenderer.setClickEnabled(true); multiRenderer.setXLabelsAngle(20); multiRenderer.setXLabelsColor(Color.WHITE); multiRenderer.setZoomButtonsVisible(false); // configure visible area multiRenderer.setXAxisMax(31); multiRenderer.setXAxisMin(1); multiRenderer.setYAxisMax(yMaxAxisValue + 30); multiRenderer.setAxisTitleTextSize(15); multiRenderer.setZoomEnabled(true); getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { graphView = ChartFactory.getLineChartView(getActivity(), dataset, multiRenderer); rlRootGraphLayout.addView(graphView, 0); if (isLeftIn) { rightIn.setDuration(1000); graphView.startAnimation(rightIn); } else { leftIn.setDuration(1000); graphView.startAnimation(leftIn); } } catch (Exception edsx) { edsx.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } ringProgressDialog.dismiss(); } }).start(); }
From source file:gov.nih.nci.firebird.service.annual.registration.AnnualRegistrationServiceBeanHibernateTest.java
@Test public void testCreatePendingRenewals() { AnnualRegistration currentRegistration = createTestRegistration(profile, configuration, DateUtils.addDays(new Date(), 61), null); AnnualRegistration expiringRegistration = createTestRegistration(profile, configuration, DateUtils.addDays(new Date(), -60), null); AnnualRegistration withdrawnExpiringRegistration = createTestRegistration(withdrawnProfile, configuration, DateUtils.addDays(new Date(), -60), null); AnnualRegistration disqualifiedExpiringRegistration = createTestRegistration(disqualifiedProfile, configuration, DateUtils.addDays(new Date(), -60), null); AnnualRegistration renewedRegistration = createTestRegistration(profile, configuration, DateUtils.addDays(new Date(), -60), null); AnnualRegistration renewal = createTestRegistration(profile, configuration, null, null); renewedRegistration.setRenewal(renewal); AnnualRegistration unsubmittedRegistration = createTestRegistration(profile, configuration, null, null); saveAndFlush(currentRegistration, expiringRegistration, withdrawnExpiringRegistration, disqualifiedExpiringRegistration, renewal, renewedRegistration, unsubmittedRegistration); bean.createPendingRenewals();//from ww w. j av a2 s . com currentRegistration = reloadObject(currentRegistration); expiringRegistration = reloadObject(expiringRegistration); withdrawnExpiringRegistration = reloadObject(withdrawnExpiringRegistration); disqualifiedExpiringRegistration = reloadObject(disqualifiedExpiringRegistration); assertNull(currentRegistration.getRenewal()); assertNotNull(expiringRegistration.getRenewal()); assertNull(withdrawnExpiringRegistration.getRenewal()); assertNull(disqualifiedExpiringRegistration.getRenewal()); assertNull(unsubmittedRegistration.getRenewal()); }
From source file:gov.nih.nci.firebird.service.task.CtepInvestigatorTasksGeneratorTest.java
@Test public void testGenerateTasks_RegistrationRenewal_OutsideNotificationWindow() throws Exception { AnnualRegistration registration = createAndAddRegistration(APPROVED); registration.setApprovalAcknowledgedByInvestigator(true); registration// ww w . j av a 2s. c o m .setDueDate(DateUtils.addDays(new Date(), DAYS_BEFORE_DUE_DATE_TO_SEND_SECOND_NOTIFICATION + 1)); List<Task> tasks = generator.generateTasks(investigator); assertTrue(tasks.isEmpty()); }
From source file:com.webbfontaine.valuewebb.action.pricedb.mp.MPCriteriaContainer.java
public static Criterion transformAgeOfPriceToPriceDate(UserCriterion ageOfPriceCriterion, UserCriterion criterionToModify) throws Exception { if (ageOfPriceCriterion.getValue() == null) { return null; }/*from ww w. j ava2s . co m*/ Date today = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); long userInputedDaysAmount = (Long) ageOfPriceCriterion.getValue(); Date todayMinusUserInputedDaysAmount = DateUtils.addDays(today, -(int) userInputedDaysAmount); criterionToModify.setValue(todayMinusUserInputedDaysAmount); String ageOfPriceCriterionCondition = ageOfPriceCriterion.getCondition(); switch (ageOfPriceCriterionCondition) { case StringConditions.GE: criterionToModify.setCondition(StringConditions.LE); break; case StringConditions.LE: criterionToModify.setCondition(StringConditions.GE); break; case StringConditions.GT: criterionToModify.setCondition(StringConditions.LT); break; case StringConditions.LT: criterionToModify.setCondition(StringConditions.GT); break; default: criterionToModify.setCondition(ageOfPriceCriterionCondition); break; } return criterionToModify.transform(); }
From source file:gov.nih.nci.firebird.service.periodic.DailyJobServiceBeanTest.java
private Date getExpectedTimerInitialDate() { Date expectedDate = new Date(); expectedDate = DateUtils.setHours(expectedDate, 3); expectedDate = DateUtils.setMinutes(expectedDate, 0); expectedDate = DateUtils.setSeconds(expectedDate, 0); expectedDate = DateUtils.setMilliseconds(expectedDate, 0); if (expectedDate.before(new Date())) { expectedDate = DateUtils.addDays(expectedDate, 1); }/*from www. j a va 2s .c o m*/ return expectedDate; }