Example usage for org.apache.commons.lang3.time DateUtils addMonths

List of usage examples for org.apache.commons.lang3.time DateUtils addMonths

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils addMonths.

Prototype

public static Date addMonths(final Date date, final int amount) 

Source Link

Document

Adds a number of months to a date returning a new object.

Usage

From source file:gov.nih.nci.firebird.data.InternshipTest.java

@Test
public void testCompareTo() throws Exception {
    assertEquals(0, internship1.compareTo(internship2));
    internship2.setEffectiveDate(DateUtils.addMonths(internship1.getEffectiveDate(), 1));
    assertTrue(internship1.compareTo(internship2) < 0);
    internship2.setEffectiveDate(DateUtils.addMonths(internship1.getEffectiveDate(), -1));
    assertTrue(internship1.compareTo(internship2) > 0);
}

From source file:gov.nih.nci.firebird.data.FellowshipTest.java

@Test
public void testCompareTo() throws Exception {
    assertEquals(0, fellowship1.compareTo(fellowship2));
    fellowship2.setEffectiveDate(DateUtils.addMonths(fellowship1.getEffectiveDate(), 1));
    assertTrue(fellowship1.compareTo(fellowship2) < 0);
    fellowship2.setEffectiveDate(DateUtils.addMonths(fellowship1.getEffectiveDate(), -1));
    assertTrue(fellowship1.compareTo(fellowship2) > 0);
}

From source file:gov.nih.nci.firebird.selenium2.tests.protocol.registration.CvTabTest.java

protected void makeLicenseExpired(FirebirdUser investigator) {
    MedicalLicense expiredLicense = investigator.getInvestigatorRole().getProfile()
            .getCredentials(MedicalLicense.class).first();
    expiredLicense.setExpirationDate(DateUtils.addMonths(new Date(), -1));
}

From source file:com.revimedia.tests.configuration.helpers.verifier.AutoRequest.java

public static void verifyA(ExtraDataAutoP extraData, LeadDataType leadDataType, String url) {
    ContactDataType contactData = leadDataType.getContactData();
    DriverType driver = leadDataType.getQuoteRequest().getDrivers().getDriver();
    InsuranceType insurance = leadDataType.getQuoteRequest().getInsurance();
    VehicleType vehicleType = leadDataType.getQuoteRequest().getVehicles().getVehicle().get(0);

    if (url.contains("?style=s")) {
        // according to the spec for [auto/a/?style=s] http://docs.revimedia.com/pages/viewpage.action?pageId=3637399
        extraData.setLeased("Yes");
        extraData.setPrimaryUse("Commute To/From Work");
        extraData.setAnnualMiles("12500");
        extraData.setExpirationDateMonth(DataHelper.getCurrentDatePlus1Month());
    }/*from   ww  w. j a  v  a 2  s. c o m*/

    //Fields from Step 1
    assertThat(vehicleType.getYear(), is(extraData.getYear()));
    assertThat(vehicleType.getMake(), is(extraData.getMake()));
    assertThat(vehicleType.getModel(), is((extraData.getModel()).replace(".", "-")));
    //Fields from Step 2
    assertThat(vehicleType.getOwnership(), is(extraData.getLeased()));
    assertThat(vehicleType.getPrimaryUse(), is(extraData.getPrimaryUse()));
    assertThat(vehicleType.getAnnualMiles(), is(extraData.getAnnualMiles()));
    //Fields from Step 3
    assertThat(insurance.getRequestedPolicy().getCoverageType(), is(extraData.getCoverageType()));
    if (extraData.getCurrentlyInsured().equalsIgnoreCase("No")) {
        extraData.setInsuranceCompany("Currently not insured");
        assertThat(insurance.getCurrentPolicy().getInsuranceCompany(), is(extraData.getInsuranceCompany()));
    } else {
        assertThat(insurance.getCurrentPolicy().getInsuranceCompany(), is(extraData.getInsuranceCompany()));
        if (url.contains("?style=s")) {
            //                assertThat(insurance.getCurrentPolicy().getExpirationDate(), is(extraData.getExpirationDateMonth()));
            assertThat(insurance.getCurrentPolicy().getExpirationDate(),
                    is(DateFormatUtils.format(DateUtils.addMonths(new Date(), 1), "yyyy-MM-dd", Locale.US)));
        } else {
            assertThat(insurance.getCurrentPolicy().getExpirationDate(),
                    is(DataHelper.dateTransformExpirationDate(extraData.getExpirationDateMonth())));
        }
        assertThat(insurance.getCurrentPolicy().getInsuredSince(),
                is(DataHelper.dateTransformInsuredSince(extraData.getInsuredSinceYears())));
    }
    //Fields from Step 4
    assertThat(driver.getMaritalStatus(), is(extraData.getMaritalStatus()));
    if (driver.getOccupation().equalsIgnoreCase("Employeed")) {
        extraData.setOccupation("Employeed");
    }
    assertThat(driver.getOccupation(), is(extraData.getOccupation()));
    assertThat(driver.getEducation(), is(extraData.getEducation()));
    assertThat(driver.getCreditRating(), is(extraData.getCreditRating()));
    if (extraData.getHomeOwner().equalsIgnoreCase("yes")) {
        extraData.setResidenceType("My own house");
    } else {
        extraData.setResidenceType("I am renting");
    }
    assertThat(contactData.getResidenceType(), is(extraData.getResidenceType()));
}

From source file:com.floreantpos.license.FiveStarPOSLicenseManager.java

/**
 * Generates a new license file returning the signature for the generated
 * license.//from w w w.  j  a v  a  2 s  .  c  o  m
 * 
 * @param templateFile
 * @param privateKey
 * @param licenseFile
 * @return String
 * @throws FileNotFoundException
 * @throws IOException
 * @throws InvalidKeyException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 * @throws SignatureException
 */
private final String generateNewLicense(File templateFile, InputStream privateKey, File licenseFile)
        throws FileNotFoundException, IOException, InvalidKeyException, NoSuchAlgorithmException,
        InvalidKeySpecException, SignatureException {

    /* reads the template file */
    Properties properties = new OrderedProperties();
    properties.load(new FileInputStream(templateFile));

    /* check if the required properties is filled */
    if (!properties.containsKey(License.LICENSED_TO)) {
        properties.put(License.LICENSED_TO, "************");
    }
    if (!properties.containsKey(License.PURCHASE_ID)) {
        properties.put(License.PURCHASE_ID, UUID.randomUUID().toString());
    }
    if (!properties.containsKey(License.PURCHASE_DATE)) {
        properties.put(License.PURCHASE_DATE, License.DATE_FORMAT.format(new Date()));
    }
    String machineKey = properties.getProperty(License.MACHINE_KEY);
    if (StringUtils.isBlank(machineKey)) {
        properties.put(License.MACHINE_KEY, getMachineKey());
    }
    if (!properties.containsKey(License.EXPIRATION_DATE)) {
        properties.put(License.EXPIRATION_DATE, License.DATE_FORMAT.format(DateUtils.addMonths(new Date(), 1)));
    }
    if (!properties.containsKey(License.BACK_OFFICE)) {
        properties.put(License.BACK_OFFICE, "false");
    }
    if (!properties.containsKey(License.KITCHEN_DISPLAY)) {
        properties.put(License.KITCHEN_DISPLAY, "false");
    }

    /* generates the license.dat file */
    return FiveStarPOSLicenseGenerator.generateLicense(properties, privateKey, licenseFile);
}

From source file:com.progym.custom.fragments.CalloriesProgressYearlyLineFragment.java

public void setYearProgressData(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  a  v a 2 s. 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(viewChart);
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }
                    }
                });

                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 January as first month
                date.setMonth(0);
                date.setDate(1);

                int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

                final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                CategorySeries seriesCallories = new CategorySeries("Callories");

                List<Ingridient> list;
                Date dt = date; // *
                for (int element : x) {
                    list = DataBaseUtils.getAllFoodConsumedInMonth(
                            Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM));

                    // init "average" data
                    int totalCallories = 0;
                    for (Ingridient ingridient : list) {
                        totalCallories += ingridient.kkal;
                    }
                    // add value to series
                    seriesCallories.add(totalCallories / daysInMonth);
                    // calculate maximum Y axis values
                    yMaxAxisValue = Math.max(yMaxAxisValue, totalCallories / daysInMonth);
                    // increment month
                    dt = DateUtils.addMonths(dt, 1);
                }

                int[] colors = new int[] { getActivity().getResources().getColor(R.color.purple) };
                final XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
                setChartSettings(renderer,
                        String.format("Callories statistic for %s year",
                                Utils.getSpecificDateValue(DATE, "yyyy")),
                        "Months", "Calories consumption", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY,
                        Color.LTGRAY);

                renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
                renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f);
                renderer.setXLabels(0);
                renderer.setClickEnabled(false);
                renderer.setZoomEnabled(false);
                renderer.setPanEnabled(false, false);
                renderer.setZoomButtonsVisible(false);
                renderer.setPanLimits(new double[] { 1, 11 });
                renderer.setShowGrid(true);
                renderer.setShowLegend(true);
                renderer.setFitLegend(true);

                for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) {
                    renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]);

                }
                dataset.addSeries(seriesCallories.toXYSeries());

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        viewChart = ChartFactory.getBarChartView(getActivity(), dataset, renderer,
                                Type.DEFAULT);
                        rlRootGraphLayout.addView(viewChart, 0);

                        if (isLeftIn) {
                            rightIn.setDuration(1000);
                            viewChart.startAnimation(rightIn);
                        } else {
                            leftIn.setDuration(1000);
                            viewChart.startAnimation(leftIn);
                        }
                    }
                });

            } catch (Exception e) {
            }
            ringProgressDialog.dismiss();
        }
    }).start();

}

From source file:com.progym.custom.fragments.FoodProgressYearlyLineFragment.java

public void setYearProgressData(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 a  v  a 2  s .  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(viewChart);
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }

                    }
                });

                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 January as first month
                date.setMonth(0);
                date.setDate(1);

                int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

                final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                CategorySeries seriesProtein = new CategorySeries("Protein");
                CategorySeries seriesFat = new CategorySeries("Fat");
                CategorySeries seriesCarbs = new CategorySeries("Carbs");

                List<Ingridient> list;
                Date dt = date;
                for (int element : x) {
                    list = DataBaseUtils.getAllFoodConsumedInMonth(
                            Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM));

                    // init "average" data
                    double totalProtein = 0, totalFat = 0, totalCarbs = 0, totalCallories = 0;
                    for (Ingridient ingridient : list) {
                        totalProtein += ingridient.protein;
                        totalFat += ingridient.fat;
                        totalCarbs += ingridient.carbohydrates;
                        totalCallories += ingridient.kkal;
                    }

                    seriesProtein.add((double) Math.round(totalProtein * 100) / 100);
                    seriesFat.add((double) Math.round(totalFat * 100) / 100);
                    seriesCarbs.add((double) Math.round(totalCarbs * 100) / 100);

                    // calculate maximum Y axis values
                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalProtein);
                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalFat);
                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalCarbs);

                    // increment month
                    dt = DateUtils.addMonths(dt, 1);
                }

                int[] colors = new int[] { getActivity().getResources().getColor(R.color.green),
                        getActivity().getResources().getColor(R.color.orange),
                        getActivity().getResources().getColor(R.color.purple) };
                final XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
                setChartSettings(renderer,
                        String.format("Protein/Carbohydrates/Fat statistic for %s year",
                                Utils.getSpecificDateValue(DATE, "yyyy")),
                        "Months", "Amount (g)           ", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY,
                        Color.LTGRAY);

                renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
                renderer.getSeriesRendererAt(1).setDisplayChartValues(true);
                renderer.getSeriesRendererAt(2).setDisplayChartValues(true);

                renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f);
                renderer.getSeriesRendererAt(1).setChartValuesTextSize(15f);
                renderer.getSeriesRendererAt(2).setChartValuesTextSize(15f);

                // renderer.getSeriesRendererAt(0).setChartValuesTextAlign(Align.CENTER);
                // renderer.getSeriesRendererAt(1).setChartValuesTextAlign(Align.LEFT);
                // renderer.getSeriesRendererAt(2).setChartValuesTextAlign(Align.RIGHT);

                renderer.setXLabels(0);
                // renderer.setYLabels(10);
                // renderer.setXLabelsAlign(Align.LEFT);
                // renderer.setYLabelsAlign(Align.LEFT);
                // renderer.setPanEnabled(true, false);
                renderer.setClickEnabled(false);
                renderer.setZoomEnabled(false);
                renderer.setPanEnabled(false, false);
                renderer.setZoomButtonsVisible(false);
                renderer.setPanLimits(new double[] { 1, 11 });
                // renderer.setZoomEnabled(false);
                // renderer.setZoomRate(1.1f);
                renderer.setShowGrid(true);
                renderer.setShowLegend(true);
                renderer.setFitLegend(true);

                for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) {
                    renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]);

                }

                dataset.addSeries(seriesProtein.toXYSeries());
                dataset.addSeries(seriesFat.toXYSeries());
                dataset.addSeries(seriesCarbs.toXYSeries());

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            viewChart = ChartFactory.getLineChartView(getActivity(), dataset,
                                    renderer/* , Type.STACKED */);
                            rlRootGraphLayout.addView(viewChart, 0);
                            if (isLeftIn) {
                                rightIn.setDuration(1000);
                                viewChart.startAnimation(rightIn);
                            } else {
                                leftIn.setDuration(1000);
                                viewChart.startAnimation(leftIn);
                            }
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }

                    }
                });

            } catch (Exception e) {
                e.printStackTrace();
            }
            ringProgressDialog.dismiss();
        }
    }).start();

}

From source file:eu.ggnet.dwoss.price.PriceCoreOperation.java

private void updateEols(List<UniqueUnit> uus) {
    Map<Product, Date> productEols = new HashMap<>();
    for (UniqueUnit uu : uus) {
        if (!productEols.containsKey(uu.getProduct())
                || productEols.get(uu.getProduct()).before(uu.getMfgDate())) {
            productEols.put(uu.getProduct(), uu.getMfgDate());
        }//from   ww  w  .jav a 2s  .  c o  m
    }
    for (Entry<Product, Date> entry : productEols.entrySet()) {
        Date eol = DateUtils.addMonths(entry.getValue(), 3);
        if (entry.getKey().getEol() == null)
            entry.getKey().setEol(eol);
        else if (entry.getKey().getEol().before(eol))
            entry.getKey().setEol(eol);
    }
}

From source file:gov.nih.nci.firebird.selenium2.tests.protocol.registration.CvTabTest.java

private void setCredentialExpirationDateInThePast(CredentialType type) {
    AbstractCredential<?> credential = Iterables
            .getFirst(dataSet.getInvestigator().getInvestigatorRole().getProfile().getCredentials(type), null);
    credential.setExpirationDate(DateUtils.addMonths(new Date(), -1));
    dataSet.update(credential);/*from w ww  .  j  a  v  a 2 s  .  co  m*/
}

From source file:gov.nih.nci.firebird.data.HumanResearchCertificateFormTest.java

@Test
public void testReturnForm_SubmittedCertificateExpired() throws CredentialAlreadyExistsException {
    registration.setStatus(RegistrationStatus.SUBMITTED);
    TrainingCertificate certificate = CredentialFactory.getInstance()
            .createCertificate(CertificateType.HUMAN_RESEARCH_CERTIFICATE);
    certificate.setExpirationDate(DateUtils.addMonths(new Date(), -1));
    registration.getProfile().addCredential(certificate);
    addProfileCertificatesToForm();//from  w  ww .j  ava 2 s.  c  om

    form.submitForm();
    assertEquals(1, form.getCertificates().size());
    assertEquals(FormStatus.SUBMITTED, form.getFormStatus());
    assertTrue(form.getCertificates().iterator().next() instanceof SubmittedTrainingCertificate);

    returnForm();
    assertEquals(FormStatus.REJECTED, form.getFormStatus());
    assertTrue(form.getCertificates().isEmpty());
}