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:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public void seekField(Granulaarsus field, int direction, int soughtValue, boolean excludingCurrent) {
    // ---------------------------------
    //  DAY_OF_MONTH
    // ---------------------------------
    if (field == Granulaarsus.DAY_OF_MONTH && direction != 0 && soughtValue == 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
        ajaFookus = nihutatudFookus;//from   ww w  . j  a va 2 s.c  o  m
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  DAY_OF_WEEK
    // ---------------------------------
    if (field == Granulaarsus.DAY_OF_WEEK && soughtValue >= DateTimeConstants.MONDAY
            && soughtValue <= DateTimeConstants.SUNDAY && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne p2ev ehk p2ev, millest tahame tingimata m66duda
        int algneNadalapaev = (excludingCurrent) ? (ajaFookus.getDayOfWeek()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale            
            ajaFookus = ajaFookus.plusDays(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusNadalapaev = ajaFookus.getDayOfWeek();
            if (algneNadalapaev != -1) {
                if (algneNadalapaev == uusNadalapaev) {
                    continue;
                } else {
                    algneNadalapaev = -1;
                }
            }
            if (uusNadalapaev == soughtValue) {
                algneNadalapaev = uusNadalapaev;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  WEEK OF YEAR
    // ---------------------------------
    if (field == Granulaarsus.WEEK_OF_YEAR && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne n2dal ehk n2dal, millest tahame m88duda
        int algneNadal = (excludingCurrent) ? (ajaFookus.getWeekOfWeekyear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale            
            ajaFookus = ajaFookus.plusDays(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusNadal = nihutatudFookus.getWeekOfWeekyear();
            if (algneNadal != -1) {
                if (algneNadal == uusNadal) {
                    continue;
                } else {
                    algneNadal = -1;
                }
            }
            if (soughtValue == 0) {
                algneNadal = uusNadal;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.WEEK_OF_YEAR, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  MONTH
    // ---------------------------------
    if (field == Granulaarsus.MONTH
            && (soughtValue == 0
                    || DateTimeConstants.JANUARY <= soughtValue && soughtValue <= DateTimeConstants.DECEMBER)
            && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne kuu ehk kuu, millest tahame m88duda
        int algneKuu = (excludingCurrent) ? (ajaFookus.getMonthOfYear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule      
            ajaFookus = ajaFookus.plusMonths(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusKuu = nihutatudFookus.getMonthOfYear();
            if (algneKuu != -1) {
                if (algneKuu == uusKuu) {
                    continue;
                } else {
                    algneKuu = -1;
                }
            }
            if (soughtValue == 0 || (soughtValue != 0 && uusKuu == soughtValue)) {
                algneKuu = uusKuu;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.MONTH, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //   YEAR
    // ---------------------------------
    if (field == Granulaarsus.YEAR && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne aasta ehk aasta, millest tahame m88duda
        int algneAasta = (excludingCurrent) ? (ajaFookus.getYear()) : (-1);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule      
            ajaFookus = ajaFookus.plusMonths(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir);
            ajaFookus = nihutatudFookus;
            int uusAasta = nihutatudFookus.getYear();
            if (algneAasta != -1) {
                if (algneAasta == uusAasta) {
                    continue;
                } else {
                    algneAasta = -1;
                }
            }
            if (soughtValue == 0) {
                algneAasta = uusAasta;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //   YEAR_OF_CENTURY
    // ---------------------------------
    if (field == Granulaarsus.YEAR_OF_CENTURY && direction != 0) {
        int minValue = SemLeidmiseAbimeetodid.getLocalDateTimeFieldExtremum(this.underlyingDate,
                DateTimeFieldType.yearOfCentury(), false);
        int maxValue = SemLeidmiseAbimeetodid.getLocalDateTimeFieldExtremum(this.underlyingDate,
                DateTimeFieldType.yearOfCentury(), true);
        if (minValue <= soughtValue && soughtValue <= maxValue) {
            int dir = (direction > 0) ? (1) : (-1);
            LocalDate ajaFookus = new LocalDate(this.underlyingDate);
            // Algne aasta ehk aasta, millest tahame m88duda
            int algneAasta = (excludingCurrent) ? (ajaFookus.getYearOfCentury()) : (-1);
            if (!excludingCurrent) {
                // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale aastale      
                ajaFookus = ajaFookus.plusYears(dir * (-1));
            }
            int count = 0;
            int cycleCount = 0;
            while (true) {
                LocalDate nihutatudFookus = ajaFookus.plusYears(1 * dir);
                cycleCount++;
                ajaFookus = nihutatudFookus;
                int uusAasta = nihutatudFookus.getYearOfCentury();
                if (algneAasta != -1) {
                    if (algneAasta == uusAasta) {
                        continue;
                    } else {
                        algneAasta = -1;
                    }
                }
                if (uusAasta == soughtValue) {
                    algneAasta = uusAasta;
                    count++;
                    if (count == Math.abs(direction)) {
                        break;
                    }
                }
            }
            this.underlyingDate = ajaFookus;
            updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION);
            functionOtherThanSetUsed = true;
            this.dateModified = true;
        }
    }
    // ---------------------------------
    //   CENTURY_OF_ERA
    // ---------------------------------
    if (field == Granulaarsus.CENTURY_OF_ERA && soughtValue == 0 && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne saj ehk sajand, millest tahame m88duda
        int algneSajand = (excludingCurrent) ? (ajaFookus.getCenturyOfEra()) : (Integer.MIN_VALUE);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale aastale      
            ajaFookus = ajaFookus.plusYears(dir * (-10));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusYears(10 * dir);
            ajaFookus = nihutatudFookus;
            int uusSajand = nihutatudFookus.getCenturyOfEra();
            if (algneSajand != Integer.MIN_VALUE) {
                if (algneSajand == uusSajand) {
                    continue;
                } else {
                    algneSajand = Integer.MIN_VALUE;
                }
            }
            if (soughtValue == 0) {
                algneSajand = uusSajand;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        updateDateRepresentation(Granulaarsus.CENTURY_OF_ERA, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }

}

From source file:gg.db.datamodel.Periods.java

License:Open Source License

/**
 * Gets the list of Period between a start date and an end date<BR/><BR/>
 * Example:<BR/>// w w w.ja  v a  2 s.  c o m
 * getListOfPeriod(new LocalDate(2006, 5, 20), new LocalDate(2006, 7, 2), PeriodType.MONTH) should create the following Period objects:
 * <UL>
 * <LI> From 05/01/2006 to 05/31/2006 (MONTH)</LI>
 * <LI> From 06/01/2006 to 06/30/2006 (MONTH)</LI>
 * <LI> From 07/01/2006 to 07/31/2006 (MONTH)</LI>
 * </UL>
 * @param start Start date of the whole period
 * @param end End date of the whole period
 * @param periodType Type of the Period to create
 * @return The list of computed Period
 */
private List<Period> getListOfPeriod(LocalDate start, LocalDate end, PeriodType periodType) {
    if (start == null || end == null || periodType == null) {
        throw new IllegalArgumentException(
                "One of the following parameters is null: 'start', 'end', 'periodType'");
    }

    // Adjust the start date to the start of the period's type (first day of the week, first day of the month, first day of the year depending on the type of the period to create)
    LocalDate startPeriods = getAdjustedStartDate(start, periodType);

    // Adjust the end date to the end of the period's type (last day of the week, last day of the month, last day of the year depending on the type of the period to create)
    LocalDate endPeriods = getAdjustedEndDate(end, periodType);

    assert (startPeriods != null && endPeriods != null);

    // Create the list of Period objects
    List<Period> listOfPeriod = new ArrayList<Period>(); // List of created Period (returned object)
    Period newPeriod;
    if (periodType == PeriodType.FREE) {
        // Create the Period object and add it to the list of Period
        newPeriod = new Period(start, end, PeriodType.FREE);
        listOfPeriod.add(newPeriod);
    } else {
        // Create all Period objects and add them to the list of Period
        while (startPeriods.compareTo(endPeriods) <= 0) {
            switch (periodType) {
            case DAY:
                // Create the DAY period
                newPeriod = new Period(startPeriods, startPeriods, PeriodType.DAY); // i.e. Day from 05/02/2006 to 05/02/2006
                startPeriods = startPeriods.plusDays(1); // Move to the next day
                break;
            case WEEK:
                // Create the WEEK period
                newPeriod = new Period(startPeriods, startPeriods.plusDays(6), PeriodType.WEEK); // i.e. Week from 05/01/2006 (MONDAY) to 05/07/2006 (SUNDAY)
                startPeriods = startPeriods.plusDays(7); // Move to the next week
                break;
            case MONTH:
                // Create the MONTH period
                newPeriod = new Period(startPeriods, startPeriods.plusMonths(1).minusDays(1), PeriodType.MONTH); // i.e. Month from 05/01/2006 to 05/31/2006
                startPeriods = startPeriods.plusMonths(1); // Move to the next month
                break;
            case YEAR:
                // Create the YEAR period
                newPeriod = new Period(startPeriods, startPeriods.plusYears(1).minusDays(1), PeriodType.YEAR); // i.e. Year from 01/01/2006 to 12/31/2006
                startPeriods = startPeriods.plusYears(1); // Move to the next year
                break;
            case FREE: // should never happen
                throw new AssertionError("The FREE PeriodType should not be handled in this switch statement");
            default: // should never happen
                throw new AssertionError("Unknown PeriodType");
            }
            assert (newPeriod != null);

            // Add the created period to the list of Period
            listOfPeriod.add(newPeriod);
        }
    }

    return listOfPeriod;
}

From source file:me.vertretungsplan.parser.ParserUtils.java

License:Mozilla Public License

static LocalDate parseDate(String string) {
    if (string == null)
        return null;
    reinitIfNeeded();//from w w w.j a  v  a 2s.c  o  m

    string = string.replace("Stand:", "").replace("Import:", "").replaceAll(", Woche [A-Z]", "").trim();
    int i = 0;
    for (DateTimeFormatter f : dateFormatters) {
        try {
            LocalDate d = f.parseLocalDate(string);
            if (dateFormats[i].contains("yyyy")) {
                return d;
            } else {
                Duration currentYearDifference = abs(new Duration(DateTime.now(), d.toDateTimeAtCurrentTime()));
                Duration lastYearDifference = abs(
                        new Duration(DateTime.now(), d.minusYears(1).toDateTimeAtCurrentTime()));
                Duration nextYearDifference = abs(
                        new Duration(DateTime.now(), d.plusYears(1).toDateTimeAtCurrentTime()));
                if (lastYearDifference.isShorterThan(currentYearDifference)) {
                    return DateTimeFormat.forPattern(dateFormats[i]).withLocale(Locale.GERMAN)
                            .withDefaultYear(f.getDefaultYear() - 1).parseLocalDate(string);
                } else if (nextYearDifference.isShorterThan(currentYearDifference)) {
                    return DateTimeFormat.forPattern(dateFormats[i]).withLocale(Locale.GERMAN)
                            .withDefaultYear(f.getDefaultYear() + 1).parseLocalDate(string);
                } else {
                    return d;
                }
            }
        } catch (IllegalArgumentException e) {
            // Does not match this format, try the next one
        }
        i++;
    }
    // Does not match any known format :(
    return null;
}

From source file:module.mobility.domain.activity.EditWorkerJobOfferInformation.java

License:Open Source License

public void setBeginDate(LocalDate beginDate) {
    this.beginDate = beginDate;
    setEndDate(beginDate.plusYears(1));
}

From source file:org.activiti.dmn.engine.impl.mvel.extension.DateUtil.java

License:Apache License

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

    LocalDate currentDate = new LocalDate(startDate);

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

    return currentDate.toDate();
}

From source file:org.apache.fineract.portfolio.account.service.StandingInstructionWritePlatformServiceImpl.java

License:Apache License

@Override
@CronTarget(jobName = JobName.EXECUTE_STANDING_INSTRUCTIONS)
public void executeStandingInstructions() throws JobExecutionException {
    Collection<StandingInstructionData> instructionDatas = this.standingInstructionReadPlatformService
            .retrieveAll(StandingInstructionStatus.ACTIVE.getValue());
    final StringBuilder sb = new StringBuilder();
    for (StandingInstructionData data : instructionDatas) {
        boolean isDueForTransfer = false;
        AccountTransferRecurrenceType recurrenceType = data.recurrenceType();
        StandingInstructionType instructionType = data.instructionType();
        LocalDate transactionDate = new LocalDate();
        if (recurrenceType.isPeriodicRecurrence()) {
            final ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator();
            PeriodFrequencyType frequencyType = data.recurrenceFrequency();
            LocalDate startDate = data.validFrom();
            if (frequencyType.isMonthly()) {
                startDate = startDate.withDayOfMonth(data.recurrenceOnDay());
                if (startDate.isBefore(data.validFrom())) {
                    startDate = startDate.plusMonths(1);
                }//w  w w.  j  a  v  a2s.  c o  m
            } else if (frequencyType.isYearly()) {
                startDate = startDate.withDayOfMonth(data.recurrenceOnDay())
                        .withMonthOfYear(data.recurrenceOnMonth());
                if (startDate.isBefore(data.validFrom())) {
                    startDate = startDate.plusYears(1);
                }
            }
            isDueForTransfer = scheduledDateGenerator.isDateFallsInSchedule(frequencyType,
                    data.recurrenceInterval(), startDate, transactionDate);

        }
        BigDecimal transactionAmount = data.amount();
        if (data.toAccountType().isLoanAccount() && (recurrenceType.isDuesRecurrence()
                || (isDueForTransfer && instructionType.isDuesAmoutTransfer()))) {
            StandingInstructionDuesData standingInstructionDuesData = this.standingInstructionReadPlatformService
                    .retriveLoanDuesData(data.toAccount().accountId());
            if (data.instructionType().isDuesAmoutTransfer()) {
                transactionAmount = standingInstructionDuesData.totalDueAmount();
            }
            if (recurrenceType.isDuesRecurrence()) {
                isDueForTransfer = new LocalDate().equals(standingInstructionDuesData.dueDate());
            }
        }

        if (isDueForTransfer && transactionAmount != null && transactionAmount.compareTo(BigDecimal.ZERO) > 0) {
            final AccountTransferDetails accountTransferDetails = this.accountTransferDetailRepository
                    .findOne(data.accountDetailId());
            final SavingsAccount fromSavingsAccount = null;
            final boolean isRegularTransaction = true;
            final boolean isExceptionForBalanceCheck = false;
            accountTransferDetails.accountTransferStandingInstruction()
                    .updateLatsRunDate(transactionDate.toDate());
            AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, transactionAmount,
                    data.fromAccountType(), data.toAccountType(), data.fromAccount().accountId(),
                    data.toAccount().accountId(), data.name() + " Standing instruction trasfer ", null, null,
                    null, null, data.toTransferType(), null, null, data.transferType().getValue(),
                    accountTransferDetails, null, null, null, null, fromSavingsAccount, isRegularTransaction,
                    isExceptionForBalanceCheck);
            transferAmount(sb, accountTransferDTO, data.getId());
        }
    }
    if (sb.length() > 0) {
        throw new JobExecutionException(sb.toString());
    }

}

From source file:org.apache.fineract.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static LocalDate getRecentEligibleMeetingDate(final String recurringRule, final LocalDate seedDate) {
    LocalDate currentDate = DateUtils.getLocalDateOfTenant();
    final Recur recur = CalendarUtils.getICalRecur(recurringRule);
    if (recur == null) {
        return null;
    }/*from ww w .j av a2 s . co m*/

    if (isValidRecurringDate(recur, seedDate, currentDate)) {
        return currentDate;
    }

    if (recur.getFrequency().equals(Recur.DAILY)) {
        currentDate = currentDate.plusDays(recur.getInterval());
    } else if (recur.getFrequency().equals(Recur.WEEKLY)) {
        currentDate = currentDate.plusWeeks(recur.getInterval());
    } else if (recur.getFrequency().equals(Recur.MONTHLY)) {
        currentDate = currentDate.plusMonths(recur.getInterval());
    } else if (recur.getFrequency().equals(Recur.YEARLY)) {
        currentDate = currentDate.plusYears(recur.getInterval());
    }

    return getNextRecurringDate(recur, seedDate, currentDate);
}

From source file:org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java

License:Apache License

public BigDecimal calculatePeriodsBetweenDates(final LocalDate startDate, final LocalDate endDate) {
    BigDecimal numberOfPeriods = BigDecimal.ZERO;
    switch (this.repaymentPeriodFrequencyType) {
    case DAYS://  www.j av  a2s  . com
        int numberOfDays = Days.daysBetween(startDate, endDate).getDays();
        numberOfPeriods = BigDecimal.valueOf((double) numberOfDays);
        break;
    case WEEKS:
        int numberOfWeeks = Weeks.weeksBetween(startDate, endDate).getWeeks();
        int daysLeftAfterWeeks = Days.daysBetween(startDate.plusWeeks(numberOfWeeks), endDate).getDays();
        numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfWeeks))
                .add(BigDecimal.valueOf((double) daysLeftAfterWeeks / 7));
        break;
    case MONTHS:
        int numberOfMonths = Months.monthsBetween(startDate, endDate).getMonths();
        LocalDate startDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths);
        LocalDate endDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths + 1);
        int daysLeftAfterMonths = Days.daysBetween(startDateAfterConsideringMonths, endDate).getDays();
        int daysInPeriodAfterMonths = Days
                .daysBetween(startDateAfterConsideringMonths, endDateAfterConsideringMonths).getDays();
        numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfMonths))
                .add(BigDecimal.valueOf((double) daysLeftAfterMonths / daysInPeriodAfterMonths));
        break;
    case YEARS:
        int numberOfYears = Years.yearsBetween(startDate, endDate).getYears();
        LocalDate startDateAfterConsideringYears = startDate.plusYears(numberOfYears);
        LocalDate endDateAfterConsideringYears = startDate.plusYears(numberOfYears + 1);
        int daysLeftAfterYears = Days.daysBetween(startDateAfterConsideringYears, endDate).getDays();
        int daysInPeriodAfterYears = Days
                .daysBetween(startDateAfterConsideringYears, endDateAfterConsideringYears).getDays();
        numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfYears))
                .add(BigDecimal.valueOf((double) daysLeftAfterYears / daysInPeriodAfterYears));
        break;
    default:
        break;
    }
    return numberOfPeriods;
}

From source file:org.apache.fineract.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 ((loanType.isJLGAccount() || loanType.isGroupAccount()) && calendar != null) {

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

    } /*** Individual or group account, or JLG not linked to a meeting ***/
    else {//from   www. ja v a2 s.  c  o 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:org.apache.fineract.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--;//  ww w. j  ava  2  s. co 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;
}