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:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

License:Apache License

private LocalDate deriveFirstRepaymentDate(final AccountType loanType, final Integer repaymentEvery,
        final LocalDate expectedDisbursementDate, final PeriodFrequencyType repaymentPeriodFrequencyType,
        final Integer minimumDaysBetweenDisbursalAndFirstRepayment, final Calendar calendar) {

    LocalDate derivedFirstRepayment = null;

    final LocalDate dateBasedOnMinimumDaysBetweenDisbursalAndFirstRepayment = expectedDisbursementDate
            .plusDays(minimumDaysBetweenDisbursalAndFirstRepayment);

    if (calendar != null) {

        final LocalDate refernceDateForCalculatingFirstRepaymentDate = expectedDisbursementDate;
        derivedFirstRepayment = deriveFirstRepaymentDateForLoans(repaymentEvery, expectedDisbursementDate,
                refernceDateForCalculatingFirstRepaymentDate, repaymentPeriodFrequencyType,
                minimumDaysBetweenDisbursalAndFirstRepayment, calendar);

    } /*** Individual or group account, or JLG not linked to a meeting ***/
    else {/*from ww  w.j av  a 2 s.co m*/
        LocalDate dateBasedOnRepaymentFrequency;
        // Derive the first repayment date as greater date among
        // (disbursement date + plus frequency) or
        // (disbursement date + minimum between disbursal and first
        // repayment )
        if (repaymentPeriodFrequencyType.isDaily()) {
            dateBasedOnRepaymentFrequency = expectedDisbursementDate.plusDays(repaymentEvery);
        } else if (repaymentPeriodFrequencyType.isWeekly()) {
            dateBasedOnRepaymentFrequency = expectedDisbursementDate.plusWeeks(repaymentEvery);
        } else if (repaymentPeriodFrequencyType.isMonthly()) {
            dateBasedOnRepaymentFrequency = expectedDisbursementDate.plusMonths(repaymentEvery);
        } /** yearly loan **/
        else {
            dateBasedOnRepaymentFrequency = expectedDisbursementDate.plusYears(repaymentEvery);
        }
        derivedFirstRepayment = dateBasedOnRepaymentFrequency.isAfter(
                dateBasedOnMinimumDaysBetweenDisbursalAndFirstRepayment) ? dateBasedOnRepaymentFrequency
                        : dateBasedOnMinimumDaysBetweenDisbursalAndFirstRepayment;
    }

    return derivedFirstRepayment;
}

From source file:com.gst.portfolio.savings.DepositAccountUtils.java

License:Apache License

public static LocalDate calculateNextDepositDate(final LocalDate lastDepositDate,
        final PeriodFrequencyType frequency, final int recurringEvery) {
    LocalDate nextDepositDate = lastDepositDate;

    switch (frequency) {
    case DAYS:/*from   www  . ja v a 2 s.com*/
        nextDepositDate = lastDepositDate.plusDays(recurringEvery);
        break;
    case WEEKS:
        nextDepositDate = lastDepositDate.plusWeeks(recurringEvery);
        break;
    case MONTHS:
        nextDepositDate = lastDepositDate.plusMonths(recurringEvery);
        break;
    case YEARS:
        nextDepositDate = lastDepositDate.plusYears(recurringEvery);
        break;
    case INVALID:
        break;
    }
    return nextDepositDate;
}

From source file:com.gst.portfolio.savings.domain.FixedDepositAccount.java

License:Apache License

public LocalDate calculateMaturityDate() {

    final LocalDate startDate = accountSubmittedOrActivationDate();
    LocalDate maturityDate = null;
    final Integer depositPeriod = this.accountTermAndPreClosure.depositPeriod();
    switch (this.accountTermAndPreClosure.depositPeriodFrequencyType()) {
    case DAYS://from   w w w.  j av a  2s.  c  o  m
        maturityDate = startDate.plusDays(depositPeriod);
        break;
    case WEEKS:
        maturityDate = startDate.plusWeeks(depositPeriod);
        break;
    case MONTHS:
        maturityDate = startDate.plusMonths(depositPeriod);
        break;
    case YEARS:
        maturityDate = startDate.plusYears(depositPeriod);
        break;
    case INVALID:
        break;
    }

    return maturityDate;
}

From source file:com.gst.portfolio.savings.domain.RecurringDepositAccount.java

License:Apache License

public LocalDate calculateMaturityDate() {

    final LocalDate startDate = depositStartDate();
    LocalDate maturityDate = null;
    final Integer depositPeriod = this.accountTermAndPreClosure.depositPeriod();
    if (depositPeriod == null) {
        return maturityDate;
    }//from  w w  w .  j  ava2 s .  c  o m
    switch (this.accountTermAndPreClosure.depositPeriodFrequencyType()) {
    case DAYS:
        maturityDate = startDate.plusDays(depositPeriod);
        break;
    case WEEKS:
        maturityDate = startDate.plusWeeks(depositPeriod);
        break;
    case MONTHS:
        maturityDate = startDate.plusMonths(depositPeriod);
        break;
    case YEARS:
        maturityDate = startDate.plusYears(depositPeriod);
        break;
    case INVALID:
        break;
    }

    return maturityDate;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

private Date calculateDateAccountIsLockedUntil(final LocalDate activationLocalDate) {

    Date lockedInUntilLocalDate = null;
    final PeriodFrequencyType lockinPeriodFrequencyType = PeriodFrequencyType
            .fromInt(this.lockinPeriodFrequencyType);
    switch (lockinPeriodFrequencyType) {
    case INVALID:
        break;//from   ww  w .  java  2s.  c  o m
    case DAYS:
        lockedInUntilLocalDate = activationLocalDate.plusDays(this.lockinPeriodFrequency).toDate();
        break;
    case WEEKS:
        lockedInUntilLocalDate = activationLocalDate.plusWeeks(this.lockinPeriodFrequency).toDate();
        break;
    case MONTHS:
        lockedInUntilLocalDate = activationLocalDate.plusMonths(this.lockinPeriodFrequency).toDate();
        break;
    case YEARS:
        lockedInUntilLocalDate = activationLocalDate.plusYears(this.lockinPeriodFrequency).toDate();
        break;
    }

    return lockedInUntilLocalDate;
}

From source file:com.gst.portfolio.savings.domain.SavingsHelper.java

License:Apache License

private LocalDate determineInterestPostingPeriodEndDateFrom(final LocalDate periodStartDate,
        final SavingsPostingInterestPeriodType interestPostingPeriodType,
        final LocalDate interestPostingUpToDate, Integer financialYearBeginningMonth) {

    LocalDate periodEndDate = interestPostingUpToDate;
    final Integer monthOfYear = periodStartDate.getMonthOfYear();
    financialYearBeginningMonth--;//from ww w  . j a  v  a2  s .  c o m
    if (financialYearBeginningMonth == 0)
        financialYearBeginningMonth = 12;

    final ArrayList<LocalDate> quarterlyDates = new ArrayList<>();
    quarterlyDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(3)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(9)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(quarterlyDates);

    final ArrayList<LocalDate> biannualDates = new ArrayList<>();
    biannualDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    biannualDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(biannualDates);
    boolean isEndDateSet = false;

    switch (interestPostingPeriodType) {
    case INVALID:
        break;
    case MONTHLY:
        // produce period end date on last day of current month
        periodEndDate = periodStartDate.dayOfMonth().withMaximumValue();
        break;
    case QUATERLY:
        for (LocalDate quarterlyDate : quarterlyDates) {
            if (quarterlyDate.isAfter(periodStartDate)) {
                periodEndDate = quarterlyDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = quarterlyDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case BIANNUAL:
        for (LocalDate biannualDate : biannualDates) {
            if (biannualDate.isAfter(periodStartDate)) {
                periodEndDate = biannualDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = biannualDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case ANNUAL:
        if (financialYearBeginningMonth < monthOfYear) {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
            periodEndDate = periodEndDate.plusYears(1);
        } else {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
        }
        periodEndDate = periodEndDate.dayOfMonth().withMaximumValue();
        break;
    }
    // interest posting always occurs on next day after the period end date.
    periodEndDate = periodEndDate.plusDays(1);
    return periodEndDate;
}

From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java

License:Apache License

private LocalDate deriveLockinPeriodDuration(final Integer lockinPeriod, final PeriodFrequencyType periodType,
        LocalDate purchaseDate) {
    LocalDate lockinDate = purchaseDate;
    if (periodType != null) {
        switch (periodType) {
        case INVALID: //It never comes in to this state.
            break;
        case DAYS:
            lockinDate = purchaseDate.plusDays(lockinPeriod);
            break;
        case WEEKS:
            lockinDate = purchaseDate.plusWeeks(lockinPeriod);
            break;
        case MONTHS:
            lockinDate = purchaseDate.plusMonths(lockinPeriod);
            break;
        case YEARS:
            lockinDate = purchaseDate.plusYears(lockinPeriod);
            break;
        }//from w w w.j a v  a 2 s .co  m
    }
    return lockinDate;
}

From source file:cz.krtinec.birthday.dto.Zodiac.java

License:Open Source License

public static Zodiac toZodiac(LocalDate birthday) {
    for (Zodiac zodiac : values()) {
        LocalDate fromWithYear = zodiac.from.withYear(birthday.getYear());
        LocalDate toWithYear = zodiac.to.withYear(birthday.getYear());

        if (birthday.getMonthOfYear() == 12 && Zodiac.CAPRICORN.equals(zodiac)) {
            toWithYear = toWithYear.plusYears(1);
        } else if (birthday.getMonthOfYear() == 1 && Zodiac.CAPRICORN.equals(zodiac)) {
            fromWithYear = fromWithYear.minusYears(1);
        }/*from w  w  w  .  jav a 2  s.com*/

        if ((fromWithYear.isBefore(birthday) || fromWithYear.isEqual(birthday))
                && (toWithYear.isAfter(birthday) || toWithYear.isEqual(birthday))) {
            return zodiac;
        }
    }

    throw new IllegalArgumentException("Cannot find zodiac sign for date: " + birthday);
}

From source file:de.appsolve.padelcampus.controller.bookings.BookingsPayMillController.java

private void addPublicApiKeyToModel(ModelAndView directDebitView) {
    PayMillConfig config = payMillConfigDAO.findFirst();
    directDebitView.addObject("PAYMILL_PUBLIC_KEY", config.getPublicApiKey());
    List<String> years = new ArrayList<>();
    LocalDate date = new LocalDate();
    years.add(date.toString("yyyy"));
    int i = 0;/*ww w. j a  va  2 s . co m*/
    while (i < 10) {
        date = date.plusYears(1);
        years.add(date.toString("yyyy"));
        i++;
    }
    directDebitView.addObject("Years", years);
}

From source file:edu.uic.apk.IDUbuilder1.java

License:Open Source License

public IDU generate_SynthNEP(HashMap<String, Object> generator_params) throws Exception {
    DrugUser modelDU = null;//from w ww.  j a  va2  s  .  c om
    Integer max_trials = 50;
    if (generator_params.containsKey("max_trials")) {
        max_trials = (Integer) generator_params.get("max_trials");
    }
    for (int trial = 0; trial < max_trials; trial++) {
        try {
            modelDU = pg.generate(generator_params);
            assert modelDU != null;
            break;
        } catch (Exception e) {
            System.out.println("x");
            modelDU = null;
        }
    }
    if (modelDU == null) {
        throw new Exception("failed to generate");
    }

    IDU idu = new IDU();
    idu.setAgeStarted(modelDU.getAgeStarted());

    LocalDate b_day = modelDU.getBirthDate();
    LocalDate age_at_survey = modelDU.getSurveyDate();
    LocalDate sim_date = APKBuilder.getSimulationDate();
    b_day = b_day.plusYears(sim_date.getYear() - age_at_survey.getYear());
    b_day = b_day.plusDays(sim_date.getDayOfYear() - age_at_survey.getDayOfYear());
    b_day = b_day.plusDays((int) (0.05 * 365 * (RandomHelper.nextDouble() - 0.5))); //some slight jitter (0.05 of a year)
    idu.setBirthDate(b_day);
    //System.out.println("Age:" + idu.getAge() + "Model age:" + modelDU.getAge());

    idu.setDatabaseLabel(modelDU.getDatabaseLabel());
    idu.setEntryDate(LocalDate.now());
    idu.setDrugGivingDegree(modelDU.getDrugGivingDegree());
    idu.setDrugReceptDegree(modelDU.getDrugReceptDegree());
    idu.setFractionReceptSharing(modelDU.getFractionReceptSharing());
    idu.setGender(modelDU.getGender());
    if (modelDU.getHcvState() == HCV_state.ABPOS) {
        double roll = RandomHelper.nextDouble() - ab_prob_chronic;
        if (roll < 0) {
            idu.setHcvInitialState(HCV_state.chronic);
        } else if (roll - ab_prob_acute < 0) {
            idu.setHcvInitialState(HCV_state.infectiousacute);
        } else {
            idu.setHcvInitialState(HCV_state.recovered);
        }
    } else {
        idu.setHcvInitialState(HCV_state.susceptible);
    }
    idu.setInjectionIntensity(modelDU.getInjectionIntensity());
    if (idu.getName() == null) {
        if (idu.getGender() == Gender.Male) {
            idu.setName(IDU.male_names[RandomHelper.nextIntFromTo(0, IDU.male_names.length - 1)]);
        } else {
            idu.setName(IDU.female_names[RandomHelper.nextIntFromTo(0, IDU.female_names.length - 1)]);
        }
    }
    idu.setPreliminaryZip(modelDU.getPreliminaryZip());
    idu.setRace(modelDU.getRace());
    idu.setSyringe_source(modelDU.getSyringe_source());
    return idu;
}