List of usage examples for org.joda.time Years yearsBetween
public static Years yearsBetween(ReadablePartial start, ReadablePartial end)
Years
representing the number of whole years between the two specified partial datetimes. From source file:com.fct.api.utils.IdcardUtils.java
License:Open Source License
public static int getAgeByBirthday(Date birthday) { LocalDate birthdayDate = new LocalDate(birthday); LocalDate now = new LocalDate(); Years age = Years.yearsBetween(birthdayDate, now); return age.getYears(); }
From source file:com.gst.portfolio.interestratechart.domain.InterestRateChartSlabFields.java
License:Apache License
public Integer depositPeriod(final LocalDate periodStartDate, final LocalDate periodEndDate) { Integer actualDepositPeriod = 0; final SavingsPeriodFrequencyType periodFrequencyType = SavingsPeriodFrequencyType.fromInt(periodType()); switch (periodFrequencyType) { case DAYS://from w w w . ja va 2s .c om 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.interestratechart.incentive.ClientAttributeIncentiveCalculation.java
License:Apache License
@Override public BigDecimal calculateIncentive(IncentiveDTO incentiveDTO) { final Client client = incentiveDTO.client(); BigDecimal interest = incentiveDTO.interest(); final InterestIncentivesFields incentivesFields = incentiveDTO.incentives(); boolean applyIncentive = false; switch (incentivesFields.attributeName()) { case GENDER://from w ww . j a v a2s .c om if (client.genderId() != null) { applyIncentive = applyIncentive(incentivesFields.conditionType(), Long.valueOf(incentivesFields.attributeValue()), client.genderId()); } break; case AGE: if (client.dateOfBirth() != null) { final LocalDate dobLacalDate = LocalDate.fromDateFields(client.dateOfBirth()); final int age = Years.yearsBetween(dobLacalDate, LocalDate.now()).getYears(); applyIncentive = applyIncentive(incentivesFields.conditionType(), Long.valueOf(incentivesFields.attributeValue()), Long.valueOf(age)); } break; case CLIENT_TYPE: if (client.clientTypeId() != null) { applyIncentive = applyIncentive(incentivesFields.conditionType(), Long.valueOf(incentivesFields.attributeValue()), client.clientTypeId()); } break; case CLIENT_CLASSIFICATION: if (client.clientClassificationId() != null) { applyIncentive = applyIncentive(incentivesFields.conditionType(), Long.valueOf(incentivesFields.attributeValue()), client.clientClassificationId()); } break; default: break; } if (applyIncentive) { switch (incentivesFields.incentiveType()) { case FIXED: interest = incentivesFields.amount(); break; case INCENTIVE: interest = interest.add(incentivesFields.amount()); break; default: break; } } return interest; }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java
License:Apache License
@Override public Boolean isDateFallsInSchedule(final PeriodFrequencyType frequency, final int repaidEvery, final LocalDate startDate, final LocalDate date) { boolean isScheduledDate = false; switch (frequency) { case DAYS://from ww w.ja v a 2 s . c o m int diff = Days.daysBetween(startDate, date).getDays(); isScheduledDate = (diff % repaidEvery) == 0; break; case WEEKS: int weekDiff = Weeks.weeksBetween(startDate, date).getWeeks(); isScheduledDate = (weekDiff % repaidEvery) == 0; if (isScheduledDate) { LocalDate modifiedDate = startDate.plusWeeks(weekDiff); isScheduledDate = modifiedDate.isEqual(date); } break; case MONTHS: int monthDiff = Months.monthsBetween(startDate, date).getMonths(); isScheduledDate = (monthDiff % repaidEvery) == 0; if (isScheduledDate) { LocalDate modifiedDate = startDate.plusMonths(monthDiff); isScheduledDate = modifiedDate.isEqual(date); } break; case YEARS: int yearDiff = Years.yearsBetween(startDate, date).getYears(); isScheduledDate = (yearDiff % repaidEvery) == 0; if (isScheduledDate) { LocalDate modifiedDate = startDate.plusYears(yearDiff); isScheduledDate = modifiedDate.isEqual(date); } break; case INVALID: break; } return isScheduledDate; }
From source file:com.gst.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:/* ww w. j a va2 s . co m*/ int numOfDays = Days.daysBetween(startDate, endDate).getDays(); numberOfPeriods = BigDecimal.valueOf((double) numOfDays); 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 = null; LocalDate endDateAfterConsideringMonths = null; int diffDays = 0; if (this.loanCalendar == null) { startDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths); startDateAfterConsideringMonths = CalendarUtils.adjustDate(startDateAfterConsideringMonths, getSeedDate(), this.repaymentPeriodFrequencyType); endDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths + 1); endDateAfterConsideringMonths = CalendarUtils.adjustDate(endDateAfterConsideringMonths, getSeedDate(), this.repaymentPeriodFrequencyType); } else { LocalDate expectedStartDate = startDate; if (!CalendarUtils.isValidRedurringDate(loanCalendar.getRecurrence(), loanCalendar.getStartDateLocalDate().minusMonths(getRepaymentEvery()), startDate)) { expectedStartDate = CalendarUtils.getNewRepaymentMeetingDate(loanCalendar.getRecurrence(), startDate.minusMonths(getRepaymentEvery()), startDate.minusMonths(getRepaymentEvery()), getRepaymentEvery(), CalendarUtils .getMeetingFrequencyFromPeriodFrequencyType(getLoanTermPeriodFrequencyType()), this.holidayDetailDTO.getWorkingDays(), isSkipRepaymentOnFirstDayOfMonth, numberOfDays); } if (!expectedStartDate.isEqual(startDate)) { diffDays = Days.daysBetween(startDate, expectedStartDate).getDays(); } if (numberOfMonths == 0) { startDateAfterConsideringMonths = expectedStartDate; } else { startDateAfterConsideringMonths = CalendarUtils.getNewRepaymentMeetingDate( loanCalendar.getRecurrence(), expectedStartDate, expectedStartDate.plusMonths(numberOfMonths), getRepaymentEvery(), CalendarUtils .getMeetingFrequencyFromPeriodFrequencyType(getLoanTermPeriodFrequencyType()), this.holidayDetailDTO.getWorkingDays(), isSkipRepaymentOnFirstDayOfMonth, numberOfDays); } endDateAfterConsideringMonths = CalendarUtils.getNewRepaymentMeetingDate( loanCalendar.getRecurrence(), startDateAfterConsideringMonths, startDateAfterConsideringMonths.plusDays(1), getRepaymentEvery(), CalendarUtils.getMeetingFrequencyFromPeriodFrequencyType(getLoanTermPeriodFrequencyType()), this.holidayDetailDTO.getWorkingDays(), isSkipRepaymentOnFirstDayOfMonth, numberOfDays); } int daysLeftAfterMonths = Days.daysBetween(startDateAfterConsideringMonths, endDate).getDays() + diffDays; 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: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 www . j a v a 2s . c om 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 www . j a va 2s . 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.inkubator.common.util.DateTimeUtil.java
/** * get total times (Age) based on date parameter * * @param birthDate input date type/*from ww w. j a v a 2 s . c om*/ * @return Integer age that calculate from today * @throws java.lang.Exception * */ public static Integer getAge(Date birthDate) throws Exception { if (birthDate.after(new Date())) { throw new Exception("Mr DHFR say :Your birthdate is newer than to day. Can't be born in the future!"); } else { DateMidnight date1 = new DateMidnight(birthDate); DateTime now = new DateTime(); Years years = Years.yearsBetween(date1, now); return years.getYears(); } }
From source file:com.inkubator.common.util.DateTimeUtil.java
/** * get total years difference, between two date type * * @return Integer// w ww . j a v a 2 s. c om * @param date1 Date reference * @param date2 Date reference */ public static Integer getTotalYearDifference(Date date1, Date date2) { return Years.yearsBetween(new DateMidnight(date1), new DateMidnight(date2)).getYears(); }
From source file:com.inkubator.hrm.web.payroll.SalaryConfirmationDetailController.java
@PostConstruct @Override/* ww w .ja v a 2 s . c om*/ public void initialization() { try { super.initialization(); ResourceBundle messages = ResourceBundle.getBundle("Messages", new Locale(FacesUtil.getSessionAttribute(HRMConstant.BAHASA_ACTIVE).toString())); String empDataId = FacesUtil.getRequestParameter("execution"); selectedPayTempKalkulasi = payTempKalkulasiService .getEntityByEmpIdAndModelTakeHomePayId(Long.parseLong(empDataId.substring(1))); WtPeriode wtPeriode = wtPeriodeService.getEntityByPayrollTypeActive(); DateMidnight date1 = new DateMidnight(selectedPayTempKalkulasi.getEmpData().getJoinDate()); DateTime now = new DateTime(wtPeriode.getUntilPeriode()); // mencari total tahun Years years = Years.yearsBetween(date1, now); //mencari total bulan Integer totalMonth = DateTimeUtil.getTotalMonthDifference( selectedPayTempKalkulasi.getEmpData().getJoinDate(), wtPeriode.getUntilPeriode()); //mencari total sisa bulan Integer totalMonthDifference = totalMonth - (12 * years.getYears()); yearMonth = years.getYears() + " " + messages.getString("global.year") + " " + totalMonthDifference + " " + messages.getString("global.month"); //list pay temp kalkulasi listPayTempKalkulasi = payTempKalkulasiService .getAllDataByEmpDataIdAndExcludeCompTHP(Long.valueOf(empDataId.substring(1))); listTempKalkulasiPajak = payTempKalkulasiEmpPajakService .getAllDataByEmpDataId(Long.valueOf(empDataId.substring(1))); listPayReceiverAccountModel = payReceiverBankAccountService .getAllDataByEmpDataId(Long.valueOf(empDataId.substring(1))); } catch (Exception ex) { LOGGER.error("Error", ex); } }