List of usage examples for org.joda.time Days daysBetween
public static Days daysBetween(ReadablePartial start, ReadablePartial end)
Days
representing the number of whole days between the two specified partial datetimes. From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java
License:Apache License
private boolean isFallingInRepaymentPeriod(LocalDate fromDate, LocalDate toDate) { boolean isSameAsRepaymentPeriod = false; if (this.interestCalculationPeriodMethod.getValue() .equals(InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD.getValue())) { switch (this.repaymentPeriodFrequencyType) { case WEEKS: int days = Days.daysBetween(fromDate, toDate).getDays(); isSameAsRepaymentPeriod = (days % 7) == 0; break; case MONTHS: boolean isFromDateOnEndDate = false; if (fromDate.getDayOfMonth() > fromDate.plusDays(1).getDayOfMonth()) { isFromDateOnEndDate = true; }/*from ww w . jav a 2s .co m*/ boolean isToDateOnEndDate = false; if (toDate.getDayOfMonth() > toDate.plusDays(1).getDayOfMonth()) { isToDateOnEndDate = true; } if (isFromDateOnEndDate && isToDateOnEndDate) { isSameAsRepaymentPeriod = true; } else { int months = getPeriodsBetween(fromDate, toDate); fromDate = fromDate.plusMonths(months); isSameAsRepaymentPeriod = fromDate.isEqual(toDate); } break; default: break; } } return isSameAsRepaymentPeriod; }
From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java
License:Apache License
public void assempleVariableScheduleFrom(final Loan loan, final String json) { this.variableLoanScheduleFromApiJsonValidator.validateSchedule(json, loan); List<LoanTermVariations> variations = loan.getLoanTermVariations(); List<LoanTermVariations> newVariations = new ArrayList<>(); extractLoanTermVariations(loan, json, newVariations); final Map<LocalDate, LocalDate> adjustDueDateVariations = new HashMap<>(); if (!variations.isEmpty()) { List<LoanTermVariations> retainVariations = adjustExistingVariations(variations, newVariations, adjustDueDateVariations); newVariations = retainVariations; }/* www .j av a2s .c o m*/ variations.addAll(newVariations); //Collections.sort(variations, new LoanTermVariationsComparator()); /* * List<LoanTermVariationsData> loanTermVariationsDatas = new * ArrayList<>(); * loanTermVariationsDatas.addAll(loanApplicationTerms.getLoanTermVariations * ().getExceptionData()); loanApplicationTerms = * LoanApplicationTerms.assembleFrom(loanApplicationTerms, * loanTermVariationsDatas); */ // date validations List<LoanRepaymentScheduleInstallment> installments = loan.getRepaymentScheduleInstallments(); Set<LocalDate> dueDates = new TreeSet<>(); LocalDate graceApplicable = loan.getExpectedDisbursedOnLocalDate(); Integer graceOnPrincipal = loan.getLoanProductRelatedDetail().graceOnPrincipalPayment(); if (graceOnPrincipal == null) { graceOnPrincipal = 0; } LocalDate lastDate = loan.getExpectedDisbursedOnLocalDate(); for (LoanRepaymentScheduleInstallment installment : installments) { dueDates.add(installment.getDueDate()); if (lastDate.isBefore(installment.getDueDate())) { lastDate = installment.getDueDate(); } if (graceOnPrincipal.equals(installment.getInstallmentNumber())) { graceApplicable = installment.getDueDate(); } } Collection<LocalDate> keySet = adjustDueDateVariations.keySet(); dueDates.addAll(keySet); for (final LocalDate date : keySet) { LocalDate removeDate = adjustDueDateVariations.get(date); if (removeDate != null) { dueDates.remove(removeDate); } } Set<LocalDate> actualDueDates = new TreeSet<>(dueDates); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("loan"); List<LocalDate> overlappings = new ArrayList<>(); for (LoanTermVariations termVariations : variations) { switch (termVariations.getTermType()) { case INSERT_INSTALLMENT: if (dueDates.contains(termVariations.fetchTermApplicaDate())) { overlappings.add(termVariations.fetchTermApplicaDate()); } else { dueDates.add(termVariations.fetchTermApplicaDate()); } if (!graceApplicable.isBefore(termVariations.fetchTermApplicaDate())) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.insert.not.allowed.before.grace.period", "Loan schedule insert request invalid"); } if (termVariations.fetchTermApplicaDate().isAfter(lastDate)) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.insert.not.allowed.after.last.period.date", "Loan schedule insert request invalid"); } else if (termVariations.fetchTermApplicaDate().isBefore(loan.getExpectedDisbursedOnLocalDate())) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.insert.not.allowed.before.disbursement.date", "Loan schedule insert request invalid"); } break; case DELETE_INSTALLMENT: if (dueDates.contains(termVariations.fetchTermApplicaDate())) { dueDates.remove(termVariations.fetchTermApplicaDate()); } else { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.remove.date.invalid", "Loan schedule remove request invalid"); } if (termVariations.fetchTermApplicaDate().isEqual(lastDate)) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.delete.not.allowed.for.last.period.date", "Loan schedule remove request invalid"); } break; case DUE_DATE: if (dueDates.contains(termVariations.fetchTermApplicaDate())) { if (overlappings.contains(termVariations.fetchTermApplicaDate())) { overlappings.remove(termVariations.fetchTermApplicaDate()); } else { dueDates.remove(termVariations.fetchTermApplicaDate()); } } else { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.modify.date.invalid", "Loan schedule modify due date request invalid"); } if (dueDates.contains(termVariations.fetchDateValue())) { overlappings.add(termVariations.fetchDateValue()); } else { dueDates.add(termVariations.fetchDateValue()); } if (termVariations.fetchDateValue().isBefore(loan.getExpectedDisbursedOnLocalDate())) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.insert.not.allowed.before.disbursement.date", "Loan schedule insert request invalid"); } if (termVariations.fetchTermApplicaDate().isEqual(lastDate)) { lastDate = termVariations.fetchDateValue(); } break; case PRINCIPAL_AMOUNT: case EMI_AMOUNT: if (!graceApplicable.isBefore(termVariations.fetchTermApplicaDate())) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.amount.update.not.allowed.before.grace.period", "Loan schedule modify request invalid"); } if (!dueDates.contains(termVariations.fetchTermApplicaDate())) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.amount.update.from.date.invalid", "Loan schedule modify request invalid"); } if (termVariations.fetchTermApplicaDate().isEqual(lastDate)) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.amount.update.not.allowed.for.last.period", "Loan schedule modify request invalid"); } break; default: break; } } if (!overlappings.isEmpty()) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( "variable.schedule.modify.date.can.not.be.due.date", overlappings); } LoanProductVariableInstallmentConfig installmentConfig = loan.loanProduct() .loanProductVariableInstallmentConfig(); final CalendarInstance loanCalendarInstance = calendarInstanceRepository .findCalendarInstaneByEntityId(loan.getId(), CalendarEntityType.LOANS.getValue()); Calendar loanCalendar = null; if (loanCalendarInstance != null) { loanCalendar = loanCalendarInstance.getCalendar(); } Boolean isSkipRepaymentOnFirstMonth = false; Integer numberOfDays = 0; boolean isSkipRepaymentOnFirstMonthEnabled = configurationDomainService .isSkippingMeetingOnFirstDayOfMonthEnabled(); if (isSkipRepaymentOnFirstMonthEnabled) { isSkipRepaymentOnFirstMonth = this.loanUtilService.isLoanRepaymentsSyncWithMeeting(loan.group(), loanCalendar); if (isSkipRepaymentOnFirstMonth) { numberOfDays = configurationDomainService.retreivePeroidInNumberOfDaysForSkipMeetingDate() .intValue(); } } final Integer minGap = installmentConfig.getMinimumGap(); final Integer maxGap = installmentConfig.getMaximumGap(); LocalDate previousDate = loan.getDisbursementDate(); for (LocalDate duedate : dueDates) { int gap = Days.daysBetween(previousDate, duedate).getDays(); previousDate = duedate; if (gap < minGap || (maxGap != null && gap > maxGap)) { baseDataValidator.reset().value(duedate).failWithCodeNoParameterAddedToErrorCode( "variable.schedule.date.must.be.in.min.max.range", "Loan schedule date invalid"); } else if (loanCalendar != null && !actualDueDates.contains(duedate) && !loanCalendar.isValidRecurringDate(duedate, isSkipRepaymentOnFirstMonth, numberOfDays)) { baseDataValidator.reset().value(duedate).failWithCodeNoParameterAddedToErrorCode( "variable.schedule.date.not.meeting.date", "Loan schedule date not in sync with meeting date"); } } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } if (loan.getExpectedFirstRepaymentOnDate() == null) { loan.setExpectedFirstRepaymentOnDate(loan.fetchRepaymentScheduleInstallment(1).getDueDate().toDate()); } final LocalDate recalculateFrom = null; ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, recalculateFrom); AppUser currentUser = this.context.getAuthenticatedUserIfPresent(); loan.regenerateRepaymentSchedule(scheduleGeneratorDTO, currentUser); }
From source file:com.gst.portfolio.loanaccount.service.LoanAccrualWritePlatformServiceImpl.java
License:Apache License
private void addAccrualTillSpecificDate(final LocalDate tilldate, final LoanScheduleAccrualData accrualData) throws Exception { LocalDate interestStartDate = accrualData.getFromDateAsLocaldate(); if (accrualData.getInterestCalculatedFrom() != null && accrualData.getFromDateAsLocaldate().isBefore(accrualData.getInterestCalculatedFrom())) { if (accrualData.getInterestCalculatedFrom().isBefore(accrualData.getDueDateAsLocaldate())) { interestStartDate = accrualData.getInterestCalculatedFrom(); } else {//from w ww .jav a2s . co m interestStartDate = accrualData.getDueDateAsLocaldate(); } } int totalNumberOfDays = Days.daysBetween(interestStartDate, accrualData.getDueDateAsLocaldate()).getDays(); LocalDate startDate = accrualData.getFromDateAsLocaldate(); if (accrualData.getInterestCalculatedFrom() != null && startDate.isBefore(accrualData.getInterestCalculatedFrom())) { if (accrualData.getInterestCalculatedFrom().isBefore(tilldate)) { startDate = accrualData.getInterestCalculatedFrom(); } else { startDate = tilldate; } } int daysToBeAccrued = Days.daysBetween(startDate, tilldate).getDays(); double interestPerDay = accrualData.getAccruableIncome().doubleValue() / totalNumberOfDays; BigDecimal amount = BigDecimal.ZERO; BigDecimal interestportion = null; BigDecimal feeportion = accrualData.getDueDateFeeIncome(); BigDecimal penaltyportion = accrualData.getDueDatePenaltyIncome(); if (daysToBeAccrued >= totalNumberOfDays) { interestportion = accrualData.getAccruableIncome(); } else { double iterest = interestPerDay * daysToBeAccrued; interestportion = BigDecimal.valueOf(iterest); } interestportion = interestportion.setScale(accrualData.getCurrencyData().decimalPlaces(), MoneyHelper.getRoundingMode()); BigDecimal totalAccInterest = accrualData.getAccruedInterestIncome(); BigDecimal totalAccPenalty = accrualData.getAccruedPenaltyIncome(); BigDecimal totalAccFee = accrualData.getAccruedFeeIncome(); if (interestportion != null) { if (totalAccInterest == null) { totalAccInterest = BigDecimal.ZERO; } interestportion = interestportion.subtract(totalAccInterest); amount = amount.add(interestportion); totalAccInterest = totalAccInterest.add(interestportion); if (interestportion.compareTo(BigDecimal.ZERO) == 0) { interestportion = null; } } if (feeportion != null) { if (totalAccFee == null) { totalAccFee = BigDecimal.ZERO; } feeportion = feeportion.subtract(totalAccFee); amount = amount.add(feeportion); totalAccFee = totalAccFee.add(feeportion); if (feeportion.compareTo(BigDecimal.ZERO) == 0) { feeportion = null; } } if (penaltyportion != null) { if (totalAccPenalty == null) { totalAccPenalty = BigDecimal.ZERO; } penaltyportion = penaltyportion.subtract(totalAccPenalty); amount = amount.add(penaltyportion); totalAccPenalty = totalAccPenalty.add(penaltyportion); if (penaltyportion.compareTo(BigDecimal.ZERO) == 0) { penaltyportion = null; } } if (amount.compareTo(BigDecimal.ZERO) == 1) { addAccrualAccounting(accrualData, amount, interestportion, totalAccInterest, feeportion, totalAccFee, penaltyportion, totalAccPenalty, tilldate); } }
From source file:com.gst.portfolio.savings.domain.DepositAccountTermAndPreClosure.java
License:Apache License
public Integer getActualDepositPeriod(final LocalDate interestPostingUpToDate, final SavingsPeriodFrequencyType periodFrequencyType) { LocalDate depositFromDate = getExpectedFirstDepositOnDate(); if (depositFromDate == null) depositFromDate = this.account.accountSubmittedOrActivationDate(); Integer actualDepositPeriod = this.depositPeriod; if (depositFromDate == null || getMaturityLocalDate() == null || interestPostingUpToDate.isEqual(getMaturityLocalDate())) { return actualDepositPeriod; }/*from w w w . j a va 2 s . com*/ final SavingsPeriodFrequencyType depositPeriodFrequencyType = periodFrequencyType; switch (depositPeriodFrequencyType) { case DAYS: actualDepositPeriod = Days.daysBetween(depositFromDate, interestPostingUpToDate).getDays(); break; case WEEKS: actualDepositPeriod = Weeks.weeksBetween(depositFromDate, interestPostingUpToDate).getWeeks(); break; case MONTHS: actualDepositPeriod = Months.monthsBetween(depositFromDate, interestPostingUpToDate).getMonths(); break; case YEARS: actualDepositPeriod = Years.yearsBetween(depositFromDate, interestPostingUpToDate).getYears(); break; case INVALID: actualDepositPeriod = this.depositPeriod;// default value break; } return actualDepositPeriod; }
From source file:com.gst.portfolio.savings.domain.DepositTermDetail.java
License:Apache License
public Integer depositPeriod(final LocalDate periodStartDate, final LocalDate periodEndDate, final SavingsPeriodFrequencyType periodFrequencyType) { Integer actualDepositPeriod = 0; switch (periodFrequencyType) { case DAYS:/*from ww w.ja va2 s . c o m*/ actualDepositPeriod = Days.daysBetween(periodStartDate, periodEndDate).getDays(); break; case WEEKS: actualDepositPeriod = Weeks.weeksBetween(periodStartDate, periodEndDate).getWeeks(); break; case MONTHS: actualDepositPeriod = Months.monthsBetween(periodStartDate, periodEndDate).getMonths(); break; case YEARS: actualDepositPeriod = Years.yearsBetween(periodStartDate, periodEndDate).getYears(); break; case INVALID: actualDepositPeriod = 0;// default value break; } return actualDepositPeriod; }
From source file:com.gst.portfolio.shareproducts.service.ShareProductDividendAssembler.java
License:Apache License
private long calculateNumberOfShareDays(final LocalDate postingDate, final LocalDate lastDividendPostDate, final int minimumActivePeriod, final Collection<ShareAccountData> shareAccountDatas, final Map<Long, Long> numberOfSharesdaysPerAccount) { long numberOfShareDays = 0; for (ShareAccountData accountData : shareAccountDatas) { long numberOfShareDaysPerAccount = 0; Collection<ShareAccountTransactionData> purchasedShares = accountData.getPurchasedShares(); long numberOfShares = 0; LocalDate lastDividendAppliedDate = null; for (ShareAccountTransactionData purchasedSharesData : purchasedShares) { final PurchasedSharesStatusType status = PurchasedSharesStatusType .fromInt(purchasedSharesData.getStatus().getId().intValue()); final PurchasedSharesStatusType type = PurchasedSharesStatusType .fromInt(purchasedSharesData.getType().getId().intValue()); if (status.isApproved() && !type.isChargePayment()) { LocalDate shareStartDate = purchasedSharesData.getPurchasedDate(); if (shareStartDate.isBefore(lastDividendPostDate)) { shareStartDate = lastDividendPostDate; }/* w w w. j a va 2 s . c o m*/ int numberOfPurchseDays = Days.daysBetween(shareStartDate, postingDate).getDays(); if (type.isPurchased() && numberOfPurchseDays < minimumActivePeriod) { continue; } if (lastDividendAppliedDate != null) { numberOfShareDaysPerAccount += (Days.daysBetween(lastDividendAppliedDate, shareStartDate) .getDays() * numberOfShares); } lastDividendAppliedDate = shareStartDate; if (type.isPurchased()) { numberOfShares += purchasedSharesData.getNumberOfShares(); } else { numberOfShares -= purchasedSharesData.getNumberOfShares(); } } } if (lastDividendAppliedDate != null) { numberOfShareDaysPerAccount += (Days.daysBetween(lastDividendAppliedDate, postingDate).getDays() * numberOfShares); } numberOfShareDays += numberOfShareDaysPerAccount; numberOfSharesdaysPerAccount.put(accountData.getId(), numberOfShareDaysPerAccount); } return numberOfShareDays; }
From source file:com.hamdikavak.humanmobility.modeling.RadiusOfGyration.java
License:Open Source License
/** * Calculates a list of progressing radius of gyration numbers based on time * unit given. Currently, day is supported. * /*from w ww . java2 s . co m*/ * @param traces * location traces of an individual * @param unit * spatial distance unit * @param timeUnit * time unit for radius of gyration calculation. Day is supported. * @return an array of calculated radius of gyration. * @throws TimeUnitNotSupportedException */ public double[] calculateRadiusOfGyrationOverTime(List<LocationTrace> traces, SpatialDistanceUnit unit, TimeUnit timeUnit) throws TimeUnitNotSupportedException { if (timeUnit != TimeUnit.DAYS) { throw new TimeUnitNotSupportedException(timeUnit + " is not supported. Please pass days as time unit."); } LocationTraceHelper traceHelper = new LocationTraceHelper(); List<LocationTrace> selectedTraces; LocalDateTime firstTraceTime = traces.get(0).getLocalTime().minusMinutes(1); LocalDateTime lastTraceTime = traces.get(traces.size() - 1).getLocalTime(); double[] rogResults; LocalDateTime curentEndDate; int numberOfDays = Days.daysBetween(firstTraceTime, lastTraceTime).getDays(); rogResults = new double[numberOfDays - 1]; for (int i = 1; i < numberOfDays; i++) { curentEndDate = firstTraceTime.plusDays(i).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); selectedTraces = traceHelper.selectBetweenDates(traces, firstTraceTime, curentEndDate); rogResults[i - 1] = calculateRadiusOfGyration(selectedTraces); } return rogResults; }
From source file:com.healthcare.DateFormatManager.java
public int getDays(Date date1, Date date2) { DateTime dt1 = new DateTime(date1); DateTime dt2 = new DateTime(date2); return Days.daysBetween(dt1, dt2).getDays(); }
From source file:com.hotmart.dragonfly.home.ui.HomeActivity.java
License:Open Source License
@Override public void onLoadFinished(Loader<CheckLastVO> loader, CheckLastVO data) { if (data != null) { DateTime date = new DateTime(data.getVerificationDate()); DateTime today = new DateTime(); int days = Days.daysBetween(date, today).getDays(); lastVerificationTime.setVisibility(View.VISIBLE); lastVerificationTime.setText(getString(R.string.x_period, days)); verification.setText(getString(R.string.last_checking)); } else {/*from ww w. j a v a 2s .co m*/ verification.setText(getString(R.string.first_check)); } }
From source file:com.hotwire.test.steps.tools.c3.overcharges.C3OverchargeModel.java
License:Open Source License
private int transformStringDateToDays(String searchPeriod) { int dateFrom; if ("last week".equalsIgnoreCase(searchPeriod)) { dateFrom = 7;//from w ww . j a va2 s.com } else if ("last 2 weeks".equalsIgnoreCase(searchPeriod)) { dateFrom = 14; } else if ("last 6 months".equalsIgnoreCase(searchPeriod)) { LocalDate date1 = new LocalDate().minusMonths(6); LocalDate date2 = new LocalDate(); dateFrom = Days.daysBetween(date1, date2).getDays(); } else { LocalDate date1 = new LocalDate().minusMonths(12); LocalDate date2 = new LocalDate(); dateFrom = Days.daysBetween(date1, date2).getDays(); } return dateFrom; }