List of usage examples for org.joda.time LocalDate plusDays
public LocalDate plusDays(int days)
From source file:org.fenixedu.academic.domain.accounting.events.AdministrativeOfficeFeeAndInsuranceEvent.java
License:Open Source License
@Override public Map<LocalDate, Money> calculateDueDateAmountMap() { final Map<LocalDate, Money> dueDateAmountMap = new HashMap<>(); final LocalDate possibleDueDate = getPossibleDueDate(); final IAdministrativeOfficeFeeAndInsurancePR officeFeeAndInsurancePR = (IAdministrativeOfficeFeeAndInsurancePR) getPostingRule(); final DateTime startDate = this.getStartDate(); final DateTime endDate = this.getEndDate(); final Money insuranceAmount = officeFeeAndInsurancePR.getInsuranceAmount(startDate, endDate); if (insuranceAmount.isPositive()) { dueDateAmountMap.put(possibleDueDate.plusDays(1), insuranceAmount); }//from w w w. j av a 2 s . c om dueDateAmountMap.put(possibleDueDate, officeFeeAndInsurancePR.getAdministrativeOfficeFeeAmount(this, startDate, endDate)); return dueDateAmountMap; }
From source file:org.fenixedu.academic.domain.accounting.installments.InstallmentForFirstTimeStudents.java
License:Open Source License
@Override public LocalDate getEndDate(final Event event) { final GratuityEvent gratuityEvent = (GratuityEvent) event; final LocalDate startDate = gratuityEvent.getEventStartDate(); return startDate.plusDays(getNumberOfDaysToStartApplyingPenalty()); }
From source file:org.fenixedu.academic.domain.phd.debts.PhdRegistrationFeePR.java
License:Open Source License
@Override protected Optional<LocalDate> getPenaltyDueDate(Event event) { final PhdRegistrationFee phdEvent = (PhdRegistrationFee) event; final PhdIndividualProgramProcess process = phdEvent.getProcess(); LocalDate whenRatified = process.getCandidacyProcess().getWhenRatified(); if (whenRatified != null) { return Optional.of(whenRatified.plusDays(20)); }//from w w w. jav a2 s . com return Optional.empty(); }
From source file:org.fenixedu.academic.task.CronSeniorStatuteGrantor.java
License:Open Source License
protected ExecutionYear specialSeasonEnrolmentPeriodOpeningSoonForThisYear(Integer howSoon) { Set<EnrolmentPeriod> enrolmentPeriods = Bennu.getInstance().getEnrolmentPeriodsSet(); Map<DegreeType, ExecutionSemester> fallTermEnrolmentPeriods = new HashMap<DegreeType, ExecutionSemester>(); Map<DegreeType, ExecutionSemester> springTermEnrolmentPeriods = new HashMap<DegreeType, ExecutionSemester>(); Map<DegreeType, ExecutionSemester> switcherTermEnrolmentPeriods = null; for (EnrolmentPeriod enrolmentPeriod : enrolmentPeriods) { if (!(enrolmentPeriod instanceof EnrolmentPeriodInSpecialSeasonEvaluations)) { continue; }/*w w w . jav a2 s . co m*/ LocalDate statuteGrantorStartDate = new LocalDate(enrolmentPeriod.getStartDateDateTime().toLocalDate()); statuteGrantorStartDate = statuteGrantorStartDate.minusWeeks(howSoon); LocalDate statuteGrantorStopDate = new LocalDate(enrolmentPeriod.getEndDateDateTime().toLocalDate()); statuteGrantorStopDate = statuteGrantorStopDate.plusDays(1); //inc 1 so that today is compared as before or equal to enrolmentPeriod end date LocalDate today = new LocalDate(); if (today.isAfter(statuteGrantorStartDate) && today.isBefore(statuteGrantorStopDate)) { if (enrolmentPeriod.getExecutionPeriod().isFirstOfYear()) { switcherTermEnrolmentPeriods = fallTermEnrolmentPeriods; } else { switcherTermEnrolmentPeriods = springTermEnrolmentPeriods; } if (enrolmentPeriod.getDegree().getDegreeType() == DegreeType.BOLONHA_DEGREE) { if (switcherTermEnrolmentPeriods.get(DegreeType.BOLONHA_DEGREE) == null) { switcherTermEnrolmentPeriods.put(DegreeType.BOLONHA_DEGREE, enrolmentPeriod.getExecutionPeriod()); } } if (enrolmentPeriod.getDegree().getDegreeType() == DegreeType.BOLONHA_MASTER_DEGREE) { if (switcherTermEnrolmentPeriods.get(DegreeType.BOLONHA_MASTER_DEGREE) == null) { switcherTermEnrolmentPeriods.put(DegreeType.BOLONHA_MASTER_DEGREE, enrolmentPeriod.getExecutionPeriod()); } } if (enrolmentPeriod.getDegree().getDegreeType() == DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) { if (switcherTermEnrolmentPeriods.get(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) == null) { switcherTermEnrolmentPeriods.put(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE, enrolmentPeriod.getExecutionPeriod()); } } } } if (fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_DEGREE) == null) { return null; } if (fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_MASTER_DEGREE) == null) { return null; } if (fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) == null) { return null; } if (springTermEnrolmentPeriods.get(DegreeType.BOLONHA_DEGREE) == null) { return null; } if (springTermEnrolmentPeriods.get(DegreeType.BOLONHA_MASTER_DEGREE) == null) { return null; } if (springTermEnrolmentPeriods.get(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) == null) { return null; } if (!(fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_DEGREE) .getExecutionYear() == springTermEnrolmentPeriods.get(DegreeType.BOLONHA_DEGREE) .getExecutionYear())) { return null; } if (!(fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_MASTER_DEGREE) .getExecutionYear() == springTermEnrolmentPeriods.get(DegreeType.BOLONHA_MASTER_DEGREE) .getExecutionYear())) { return null; } if (!(fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) .getExecutionYear() == springTermEnrolmentPeriods.get(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) .getExecutionYear())) { return null; } if (!(fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_DEGREE) == fallTermEnrolmentPeriods .get(DegreeType.BOLONHA_MASTER_DEGREE))) { return null; } if (!(fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_DEGREE) == fallTermEnrolmentPeriods .get(DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE))) { return null; } return fallTermEnrolmentPeriods.get(DegreeType.BOLONHA_DEGREE).getExecutionYear(); }
From source file:org.fenixedu.treasury.domain.tariff.InterestRate.java
License:Open Source License
private InterestRateBean calculateDaily(final Map<LocalDate, BigDecimal> createdInterestEntries, final LocalDate dueDate, final LocalDate paymentDate, final TreeMap<LocalDate, BigDecimal> sortedMap) { final InterestRateBean result = new InterestRateBean(getInterestType()); BigDecimal totalInterestAmount = BigDecimal.ZERO; int totalOfDays = 0; LocalDate startDate = applyOnFirstWorkdayIfNecessary( dueDate.plusDays(numberOfDaysAfterDueDate(dueDate.getYear()))); // Iterate over amountInDebtMap and calculate amountToPay BigDecimal amountInDebt = BigDecimal.ZERO; for (final Entry<LocalDate, BigDecimal> entry : sortedMap.entrySet()) { if (entry.getKey().isAfter(paymentDate)) { break; }/*from ww w . j a v a2 s. c o m*/ if (entry.getKey().isBefore(startDate)) { amountInDebt = entry.getValue(); continue; } final LocalDate endDate = entry.getKey(); int numberOfDays = 0; BigDecimal partialInterestAmount; if (startDate.getYear() != endDate.getYear()) { boolean reachedMaxDays = false; int firstYearDays = Days.daysBetween(startDate, Constants.lastDayInYear(startDate.getYear())) .getDays() + 1; int secondYearDays = Days.daysBetween(Constants.firstDayInYear(endDate.getYear()), endDate) .getDays() + 1; { if (isMaximumDaysToApplyPenaltyApplied() && totalOfDays + firstYearDays >= getMaximumDaysToApplyPenalty()) { firstYearDays = getMaximumDaysToApplyPenalty() - totalOfDays; reachedMaxDays = true; } final BigDecimal amountPerDay = Constants.divide(amountInDebt, new BigDecimal(Constants.numberOfDaysInYear(startDate.getYear()))); final BigDecimal rate = interestRate(startDate.getYear()); partialInterestAmount = Constants.divide(rate, Constants.HUNDRED_PERCENT).multiply(amountPerDay) .multiply(new BigDecimal(firstYearDays)); numberOfDays += firstYearDays; if (Constants.isPositive(partialInterestAmount)) { result.addDetail(partialInterestAmount, startDate, Constants.lastDayInYear(startDate.getYear()), amountPerDay, amountInDebt); } } if (!reachedMaxDays) { if (isMaximumDaysToApplyPenaltyApplied() && totalOfDays + firstYearDays + secondYearDays >= getMaximumDaysToApplyPenalty()) { secondYearDays = getMaximumDaysToApplyPenalty() - totalOfDays - firstYearDays; } final BigDecimal amountPerDay = Constants.divide(amountInDebt, new BigDecimal(Constants.numberOfDaysInYear(endDate.getYear()))); final BigDecimal rate = interestRate(endDate.getYear()); final BigDecimal secondInterestAmount = Constants.divide(rate, Constants.HUNDRED_PERCENT) .multiply(amountPerDay).multiply(new BigDecimal(secondYearDays)); if (Constants.isPositive(partialInterestAmount)) { result.addDetail(secondInterestAmount, Constants.firstDayInYear(endDate.getYear()), endDate, amountPerDay, amountInDebt); } partialInterestAmount = partialInterestAmount.add(secondInterestAmount); numberOfDays += secondYearDays; } } else { numberOfDays = Days.daysBetween(startDate, endDate).getDays() + 1; if (isMaximumDaysToApplyPenaltyApplied() && totalOfDays + numberOfDays >= getMaximumDaysToApplyPenalty()) { numberOfDays = getMaximumDaysToApplyPenalty() - totalOfDays; } final BigDecimal amountPerDay = Constants.divide(amountInDebt, new BigDecimal(Constants.numberOfDaysInYear(startDate.getYear()))); final BigDecimal rate = interestRate(startDate.getYear()); partialInterestAmount = Constants.divide(rate, Constants.HUNDRED_PERCENT).multiply(amountPerDay) .multiply(new BigDecimal(numberOfDays)); if (Constants.isPositive(partialInterestAmount)) { result.addDetail(partialInterestAmount, startDate, endDate, amountPerDay, amountInDebt); } } totalInterestAmount = totalInterestAmount.add(partialInterestAmount); totalOfDays += numberOfDays; amountInDebt = entry.getValue(); startDate = endDate.plusDays(1); if (isMaximumDaysToApplyPenaltyApplied() && totalOfDays >= getMaximumDaysToApplyPenalty()) { break; } } if (createdInterestEntries != null) { final TreeMap<LocalDate, BigDecimal> interestSortedMap = new TreeMap<LocalDate, BigDecimal>(); interestSortedMap.putAll(createdInterestEntries); for (final Entry<LocalDate, BigDecimal> entry : createdInterestEntries.entrySet()) { result.addCreatedInterestEntry(entry.getKey(), entry.getValue()); totalInterestAmount = totalInterestAmount.subtract(entry.getValue()); } } result.setInterestAmount(getRelatedCurrency().getValueWithScale(totalInterestAmount)); result.setNumberOfDays(totalOfDays); return result; }
From source file:org.fenixedu.treasury.domain.tariff.InterestRate.java
License:Open Source License
private LocalDate applyOnFirstWorkdayIfNecessary(final LocalDate date) { if (isApplyInFirstWorkday() && isSaturday(date)) { return date.plusDays(1); } else if (isApplyInFirstWorkday() && isSunday(date)) { return date.plusDays(1); }/* w ww . j a v a 2 s . co m*/ return date; }
From source file:org.fenixedu.treasury.domain.tariff.Tariff.java
License:Open Source License
public LocalDate dueDate(final LocalDate requestDate) { if (getDueDateCalculationType().isFixedDate()) { return getFixedDueDate(); }/* w ww.ja va 2 s . c o m*/ if (getDueDateCalculationType().isBestOfFixedDateAndDaysAfterCreation()) { final LocalDate daysAfterCreation = requestDate.plusDays(getNumberOfDaysAfterCreationForDueDate()); if (daysAfterCreation.isAfter(getFixedDueDate())) { return daysAfterCreation; } else { return getFixedDueDate(); } } return requestDate.plusDays(getNumberOfDaysAfterCreationForDueDate()); }
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.freewheelschedule.freewheel.common.model.TimedTrigger.java
License:Apache License
private void setNextRunDay() { LocalDate nextCandidate = new LocalDate(); LocalDate nextRunDay = null;// ww w. j a va2 s .c o m while (nextRunDay == null) { nextCandidate = nextCandidate.plusDays(1); if (DayOfWeek.valueOf(nextCandidate.dayOfWeek().getAsText().toUpperCase()).matches(daysOfWeek)) { nextRunDay = nextCandidate; } } runDate = nextRunDay; }
From source file:org.gnucash.android.ui.transaction.TransactionsActivity.java
License:Apache License
/** * Formats the date to show the the day of the week if the {@code dateMillis} is within 7 days * of today. Else it shows the actual date formatted as short string. <br> * It also shows "today", "yesterday" or "tomorrow" if the date is on any of those days * @param dateMillis//from w w w . j a va 2 s. c o m * @return */ @NonNull public static String getPrettyDateFormat(Context context, long dateMillis) { LocalDate transactionTime = new LocalDate(dateMillis); LocalDate today = new LocalDate(); String prettyDateText = null; if (transactionTime.compareTo(today.minusDays(1)) >= 0 && transactionTime.compareTo(today.plusDays(1)) <= 0) { prettyDateText = DateUtils .getRelativeTimeSpanString(dateMillis, System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS) .toString(); } else if (transactionTime.getYear() == today.getYear()) { prettyDateText = mDayMonthDateFormat.format(new Date(dateMillis)); } else { prettyDateText = DateUtils.formatDateTime(context, dateMillis, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_YEAR); } return prettyDateText; }