Example usage for org.joda.time LocalDate plusYears

List of usage examples for org.joda.time LocalDate plusYears

Introduction

In this page you can find the example usage for org.joda.time LocalDate plusYears.

Prototype

public LocalDate plusYears(int years) 

Source Link

Document

Returns a copy of this date plus the specified number of years.

Usage

From source file:org.apache.isis.core.metamodel.facets.value.datejodalocal.JodaLocalDateUtil.java

License:Apache License

private static LocalDate add(final LocalDate original, final int years, final int months, final int days,
        final int hours, final int minutes) {
    if (hours != 0 || minutes != 0) {
        throw new IllegalArgumentException("cannot add non-zero hours or minutes to a LocalDate");
    }//from   ww  w.  j  av  a 2  s  .  com
    return original.plusYears(years).plusMonths(months).plusDays(days);
}

From source file:org.apache.isis.core.progmodel.facets.value.datejodalocal.JodaLocalDateValueSemanticsProvider.java

License:Apache License

@Override
protected LocalDate add(final LocalDate original, final int years, final int months, final int days,
        final int hours, final int minutes) {
    if (hours != 0 || minutes != 0) {
        throw new IllegalArgumentException("cannot add non-zero hours or minutes to a LocalDate");
    }//  ww  w.ja va  2  s . co  m
    return original.plusYears(years).plusMonths(months).plusDays(days);
}

From source file:org.egov.tl.service.ValidityService.java

License:Open Source License

private void applyLicenseExpiryBasedOnCustomValidity(TradeLicense license, Validity validity) {
    LocalDate nextExpiryDate = new LocalDate(license.isNewApplication() ? license.getCommencementDate()
            : license.getCurrentDemand().getEgInstallmentMaster().getFromDate());
    if (validity.getYear() != null && validity.getYear() > 0)
        nextExpiryDate = nextExpiryDate.plusYears(validity.getYear());
    if (validity.getMonth() != null && validity.getMonth() > 0)
        nextExpiryDate = nextExpiryDate.plusMonths(validity.getMonth());
    if (validity.getWeek() != null && validity.getWeek() > 0)
        nextExpiryDate = nextExpiryDate.plusWeeks(validity.getWeek());
    if (validity.getDay() != null && validity.getDay() > 0)
        nextExpiryDate = nextExpiryDate.plusDays(validity.getDay());
    license.setDateOfExpiry(nextExpiryDate.toDate());
}

From source file:org.fenixedu.treasury.domain.tariff.InterestRate.java

License:Open Source License

private TreeMap<LocalDate, BigDecimal> splitDatesWithYearsSpan(final TreeMap<LocalDate, BigDecimal> sortedMap) {

    final TreeMap<LocalDate, BigDecimal> result = new TreeMap<LocalDate, BigDecimal>();
    LocalDate startDate = null;

    for (final Entry<LocalDate, BigDecimal> entry : sortedMap.entrySet()) {
        if (startDate == null) {
            result.put(entry.getKey(), entry.getValue());
            startDate = entry.getKey();//from   ww  w.  j  a  va  2 s.c o  m
            continue;
        }

        if (startDate.getYear() == entry.getKey().getYear()) {
            result.put(entry.getKey(), entry.getValue());
            startDate = entry.getKey();
            continue;
        }

        if (startDate.getYear() == entry.getKey().getYear() - 1) {
            result.put(entry.getKey(), entry.getValue());
            startDate = entry.getKey();
            continue;
        }

        for (LocalDate a = startDate.plusYears(1), b = entry.getKey(); a.getYear() < b.getYear();) {
            result.put(Constants.firstDayInYear(a.getYear()), sortedMap.get(startDate));
            a = a.plusYears(1);
        }

        result.put(entry.getKey(), entry.getValue());
        startDate = entry.getKey();
    }

    return result;
}

From source file:org.flowable.dmn.engine.impl.el.util.DateUtil.java

License:Apache License

public static Date addDate(Object startDate, Object years, Object months, Object days) {

    LocalDate currentDate = new LocalDate(startDate);

    currentDate = currentDate.plusYears(intValue(years));
    currentDate = currentDate.plusMonths(intValue(months));
    currentDate = currentDate.plusDays(intValue(days));

    return currentDate.toDate();
}

From source file:org.gnucash.android.ui.report.linechart.CashFlowLineChartFragment.java

License:Apache License

/**
 * Returns a data object that represents a user data of the specified account types
 * @param accountTypeList account's types which will be displayed
 * @return a {@code LineData} instance that represents a user data
 *///  w  w  w . j a  v a2s  .c om
private LineData getData(List<AccountType> accountTypeList) {
    Log.w(TAG, "getData");
    calculateEarliestAndLatestTimestamps(accountTypeList);
    // LocalDateTime?
    LocalDate startDate;
    LocalDate endDate;
    if (mReportPeriodStart == -1 && mReportPeriodEnd == -1) {
        startDate = new LocalDate(mEarliestTransactionTimestamp).withDayOfMonth(1);
        endDate = new LocalDate(mLatestTransactionTimestamp).withDayOfMonth(1);
    } else {
        startDate = new LocalDate(mReportPeriodStart).withDayOfMonth(1);
        endDate = new LocalDate(mReportPeriodEnd).withDayOfMonth(1);
    }

    int count = getDateDiff(new LocalDateTime(startDate.toDate().getTime()),
            new LocalDateTime(endDate.toDate().getTime()));
    Log.d(TAG, "X-axis count" + count);
    List<String> xValues = new ArrayList<>();
    for (int i = 0; i <= count; i++) {
        switch (mGroupInterval) {
        case MONTH:
            xValues.add(startDate.toString(X_AXIS_PATTERN));
            Log.d(TAG, "X-axis " + startDate.toString("MM yy"));
            startDate = startDate.plusMonths(1);
            break;
        case QUARTER:
            int quarter = getQuarter(new LocalDateTime(startDate.toDate().getTime()));
            xValues.add("Q" + quarter + startDate.toString(" yy"));
            Log.d(TAG, "X-axis " + "Q" + quarter + startDate.toString(" MM yy"));
            startDate = startDate.plusMonths(3);
            break;
        case YEAR:
            xValues.add(startDate.toString("yyyy"));
            Log.d(TAG, "X-axis " + startDate.toString("yyyy"));
            startDate = startDate.plusYears(1);
            break;
        //                default:
        }
    }

    List<LineDataSet> dataSets = new ArrayList<>();
    for (AccountType accountType : accountTypeList) {
        LineDataSet set = new LineDataSet(getEntryList(accountType), accountType.toString());
        set.setDrawFilled(true);
        set.setLineWidth(2);
        set.setColor(COLORS[dataSets.size()]);
        set.setFillColor(FILL_COLORS[dataSets.size()]);

        dataSets.add(set);
    }

    LineData lineData = new LineData(xValues, dataSets);
    if (lineData.getYValueSum() == 0) {
        mChartDataPresent = false;
        return getEmptyData();
    }
    return lineData;
}

From source file:org.gnucash.android.ui.report.LineChartFragment.java

License:Apache License

/**
 * Returns a data object that represents a user data of the specified account types
 * @param accountTypeList account's types which will be displayed
 * @return a {@code LineData} instance that represents a user data
 *///w w  w  .  j av a  2 s . c  o  m
private LineData getData(List<AccountType> accountTypeList) {
    Log.w(TAG, "getData");
    calculateEarliestAndLatestTimestamps(accountTypeList);
    // LocalDateTime?
    LocalDate startDate;
    LocalDate endDate;
    if (mReportStartTime == -1 && mReportEndTime == -1) {
        startDate = new LocalDate(mEarliestTransactionTimestamp).withDayOfMonth(1);
        endDate = new LocalDate(mLatestTransactionTimestamp).withDayOfMonth(1);
    } else {
        startDate = new LocalDate(mReportStartTime).withDayOfMonth(1);
        endDate = new LocalDate(mReportEndTime).withDayOfMonth(1);
    }

    int count = getDateDiff(new LocalDateTime(startDate.toDate().getTime()),
            new LocalDateTime(endDate.toDate().getTime()));
    Log.d(TAG, "X-axis count" + count);
    List<String> xValues = new ArrayList<>();
    for (int i = 0; i <= count; i++) {
        switch (mGroupInterval) {
        case MONTH:
            xValues.add(startDate.toString(X_AXIS_PATTERN));
            Log.d(TAG, "X-axis " + startDate.toString("MM yy"));
            startDate = startDate.plusMonths(1);
            break;
        case QUARTER:
            int quarter = getQuarter(new LocalDateTime(startDate.toDate().getTime()));
            xValues.add("Q" + quarter + startDate.toString(" yy"));
            Log.d(TAG, "X-axis " + "Q" + quarter + startDate.toString(" MM yy"));
            startDate = startDate.plusMonths(3);
            break;
        case YEAR:
            xValues.add(startDate.toString("yyyy"));
            Log.d(TAG, "X-axis " + startDate.toString("yyyy"));
            startDate = startDate.plusYears(1);
            break;
        //                default:
        }
    }

    List<LineDataSet> dataSets = new ArrayList<>();
    for (AccountType accountType : accountTypeList) {
        LineDataSet set = new LineDataSet(getEntryList(accountType), accountType.toString());
        set.setDrawFilled(true);
        set.setLineWidth(2);
        set.setColor(COLORS[dataSets.size()]);
        set.setFillColor(FILL_COLORS[dataSets.size()]);

        dataSets.add(set);
    }

    LineData lineData = new LineData(xValues, dataSets);
    if (lineData.getYValueSum() == 0) {
        mChartDataPresent = false;
        return getEmptyData();
    }
    return lineData;
}

From source file:org.icgc.dcc.storage.client.ssl.ClientKeyTool.java

License:Open Source License

@SneakyThrows
private Certificate createCertificate(KeyPair keyPair) {
    LocalDate today = LocalDate.now();
    X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(x500Name,
            BigInteger.valueOf(sr.nextInt(Integer.MAX_VALUE)), today.minusDays(1).toDate(),
            today.plusYears(3).toDate(), x500Name, keyPair.getPublic());
    ContentSigner sigGen = new JcaContentSignerBuilder(SHA256_WITH_RSA_ENCRYPTION).setProvider(BC)
            .build(keyPair.getPrivate());
    X509Certificate cert = new JcaX509CertificateConverter().setProvider(BC)
            .getCertificate(certGen.build(sigGen));
    return cert;//from  www. j ava 2s  . c  o m
}

From source file:org.kitodo.production.forms.CalendarForm.java

License:Open Source License

/**
 * The function checkBlockPlausibility compares the dates entered against
 * some plausibility assumptions and sets hints otherwise.
 *//*www .j a  v  a2s  .c  om*/
private void checkBlockPlausibility() {
    LocalDate firstAppearance = blockShowing.getFirstAppearance();
    LocalDate lastAppearance = blockShowing.getLastAppearance();
    if (Objects.nonNull(firstAppearance) && Objects.nonNull(lastAppearance)) {
        if (firstAppearance.plusYears(100).isBefore(lastAppearance)) {
            Helper.setMessage(BLOCK + "long");
        }
        if (firstAppearance.isAfter(lastAppearance)) {
            Helper.setErrorMessage(BLOCK_NEGATIVE);
        }
        if (firstAppearance.isBefore(START_RELATION)) {
            Helper.setMessage(BLOCK + "firstAppearance.early");
        }
        if (firstAppearance.isAfter(today)) {
            Helper.setMessage(BLOCK + "firstAppearance.fiction");
        }
        if (lastAppearance.isBefore(START_RELATION)) {
            Helper.setMessage(BLOCK + "lastAppearance.early");
        }
        if (lastAppearance.isAfter(today)) {
            Helper.setMessage(BLOCK + "lastAppearance.fiction");
        }
    }
}

From source file:org.kuali.kpme.core.accrualcategory.rule.service.AccrualCategoryRuleServiceImpl.java

License:Educational Community License

public AccrualCategoryRule getAccrualCategoryRuleForDate(AccrualCategory accrualCategory, LocalDate currentDate,
        LocalDate serviceDate) {/*from   w  w  w . j  a v a  2 s .c  o  m*/
    if (serviceDate == null) {
        return null;
    }
    List<AccrualCategoryRule> acrList = this
            .getActiveAccrualCategoryRules(accrualCategory.getLmAccrualCategoryId());
    for (AccrualCategoryRule acr : acrList) {
        String uot = acr.getServiceUnitOfTime();
        int startTime = acr.getStart().intValue();
        int endTime = acr.getEnd().intValue();

        LocalDate startDate = serviceDate;
        LocalDate endDate = serviceDate;
        if (uot.equals("M")) { // monthly
            startDate = startDate.plusMonths(startTime);
            endDate = endDate.plusMonths(endTime).minusDays(1);
        } else if (uot.endsWith("Y")) { // yearly
            startDate = startDate.plusYears(startTime);
            endDate = endDate.plusYears(endTime).minusDays(1);
        }

        // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
        if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
            startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
        }
        if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
            endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
        }

        if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
            return acr;
        }
    }
    return null;
}