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

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

Introduction

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

Prototype

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

Source Link

Document

Sets the years field to a date returning a new object.

Usage

From source file:eu.ggnet.dwoss.report.assist.gen.ReportLineGenerator.java

/**
 * Makes one special Reportline//from  www  .  j ava2s  .com
 * <p/>
 * @param contractors  the contractor
 * @param posTypes     the allowed types of positions
 * @param starting     a starting date, this is the earlies date a line will have the reporting date set
 * @param maxDeltaDays this is a max delta for days of the reporting date. The date will be between starting and starting+maxDeltaDays.
 * @param docTypes     documetTypes
 * @return the ReportingLine
 */
public ReportLine makeReportLine(List<TradeName> contractors, Date starting, int maxDeltaDays,
        List<PositionType> posTypes, List<DocumentType> docTypes) {
    ReportLine line = new ReportLine();
    line.setName("ReportLine-" + getRandomInt());
    line.setDescription("desription-" + getRandomInt());
    line.setDossierId(getRandomLong());
    line.setDocumentIdentifier("dossierIdentifier-" + getRandomInt());
    line.setDocumentId(getRandomLong());
    line.setDocumentIdentifier("documentIdentifier-" + getRandomInt());
    line.setPositionType(posTypes.get(R.nextInt(posTypes.size())));
    line.setDocumentType(docTypes.get(R.nextInt(docTypes.size())));
    line.setCustomerId(getRandomLong());
    line.setContractorPartNo("123.456");

    line.setAmount(getRandomLong());
    double tax = GlobalConfig.TAX;
    double price = Math.abs(R.nextDouble() * R.nextInt(1500));
    line.setManufacturerCostPrice(price * 1.10);
    line.setContractorReferencePrice(price * 1.10);
    line.setAfterTaxPrice(price + (price * tax));
    line.setPrice(price);
    line.setTax(tax);

    line.setBookingAccount(getRandomInt());
    GeneratedAddress makeAddress = new NameGenerator().makeAddress();
    Name makeName = new NameGenerator().makeName();
    String name = makeName.getFirst() + " " + makeName.getLast();
    line.setCustomerName(name);
    String invoiceAdress = name + ", " + makeAddress.getStreet() + " " + makeAddress.getNumber() + ", "
            + makeAddress.getPostalCode() + " " + makeAddress.getTown();
    line.setCustomerCompany(R.nextInt(10) < 7 ? "" : "TestFirma");
    line.setInvoiceAddress(invoiceAdress);
    line.setRefurbishId("" + R.nextInt(100000));
    line.setUniqueUnitId(getRandomLong());
    line.setSerial("serial" + getRandomInt());
    line.setProductId(getRandomLong());
    line.setPartNo("partNo" + getRandomInt());
    line.setContractor(
            contractors.size() == 1 ? contractors.get(0) : contractors.get(R.nextInt(contractors.size())));
    line.setProductBrand(brands.get(R.nextInt(brands.size())));

    Date pastFiveYears = DateUtils.setYears(new Date(), 2009);
    line.setMfgDate(DateUtils.addDays(pastFiveYears, R.nextInt(2000)));

    line.setReportingDate(maxDeltaDays > 0 ? DateUtils.addDays(starting, R.nextInt(maxDeltaDays)) : starting);

    return line;
}

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);//  w w w .  j av a  2  s .com
    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:org.rippleosi.common.util.DateFormatter.java

public static Date toTimeOnly(String input) {
    Date date = toDate(input);//from  w  ww  .  j  a  v a 2  s .com
    if (date != null) {
        date = DateUtils.setYears(date, 1970);
        date = DateUtils.setMonths(date, 0);
        date = DateUtils.setDays(date, 1);

        return date;
    }

    return null;
}

From source file:pl.bcichecki.rms.client.android.activities.EditEventActivity.java

private void showEndsOnDateDialog() {
    Calendar endDateCalendar = Calendar.getInstance();
    endDateCalendar.setTime(endDate);/*from  www .  jav a 2  s .c  o m*/

    OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            endDate = DateUtils.setYears(endDate, year);
            endDate = DateUtils.setMonths(endDate, monthOfYear);
            endDate = DateUtils.setDays(endDate, dayOfMonth);
            updateEndDateButtons();
        }
    };

    DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener,
            endDateCalendar.get(Calendar.YEAR), endDateCalendar.get(Calendar.MONTH),
            endDateCalendar.get(Calendar.DAY_OF_MONTH));
    datePickerDialog.setTitle(R.string.activity_edit_event_pick_end_date);
    datePickerDialog.show();
}

From source file:pl.bcichecki.rms.client.android.activities.EditEventActivity.java

private void showStartsOnDateDialog() {
    Calendar startDateCalendar = Calendar.getInstance();
    startDateCalendar.setTime(startDate);

    OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

        @Override//from w  ww  . j  av  a 2 s  .  c o m
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            long diff = endDate.getTime() - startDate.getTime();

            startDate = DateUtils.setYears(startDate, year);
            startDate = DateUtils.setMonths(startDate, monthOfYear);
            startDate = DateUtils.setDays(startDate, dayOfMonth);
            updateStartDateButtons();

            endDate.setTime(startDate.getTime() + diff);
            updateEndDateButtons();
        }
    };

    DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener,
            startDateCalendar.get(Calendar.YEAR), startDateCalendar.get(Calendar.MONTH),
            startDateCalendar.get(Calendar.DAY_OF_MONTH));
    datePickerDialog.setTitle(R.string.activity_edit_event_pick_start_date);
    datePickerDialog.show();
}

From source file:uk.gov.hscic.common.util.DateFormatter.java

public static Date toTimeOnly(final String input) {
    Date date = toDate(input);//from   www.  j  a  va2 s.  com

    if (date != null) {
        date = DateUtils.setYears(date, 1970);
        date = DateUtils.setMonths(date, 0);
        date = DateUtils.setDays(date, 1);

        return date;
    }

    return null;
}

From source file:yoyo.actor.screen.iface.jsf.converter.DateConverter.java

/**
 * Create date.// w  w w . j ava 2 s . c  o  m
 * @param aDateText date text
 * @return created date
 * @throws ParseException parse exception
 */
private static Date createDate(final String aDateText) throws ParseException {
    final Calendar cal = Calendar.getInstance();
    final Date now = cal.getTime();
    Date date = DateUtils.parseDateStrictly(aDateText,
            new String[] { FORMAL_PATTERN, "yyyyMMdd", "yyMMdd", "MMdd", "dd" });
    if (aDateText.length() == LENGTH_MMDD) {
        date = DateUtils.setYears(date, cal.get(Calendar.YEAR));
        if (date.before(now)) {
            date = DateUtils.addYears(date, 1);
        }
    } else if (aDateText.length() == LENGTH_DD) {
        date = DateUtils.setYears(date, cal.get(Calendar.YEAR));
        date = DateUtils.setMonths(date, cal.get(Calendar.MONTH));
        if (date.before(now)) {
            date = DateUtils.addMonths(date, 1);
        }
    }
    return date;
}