List of usage examples for org.joda.time LocalDateTime plusSeconds
public LocalDateTime plusSeconds(int seconds)
From source file:com.axelor.apps.crm.service.EventService.java
License:Open Source License
public LocalDateTime computeEndDateTime(LocalDateTime startDateTime, int duration) { return startDateTime.plusSeconds(duration); }
From source file:com.axelor.csv.script.ImportDateTime.java
License:Open Source License
public LocalDateTime updateSecond(LocalDateTime dateTime, String second) { if (!Strings.isNullOrEmpty(second)) { Matcher matcher = patternMonth.matcher(second); if (matcher.find()) { Integer seconds = Integer.parseInt(matcher.group()); if (second.startsWith("+")) dateTime = dateTime.plusSeconds(seconds); else if (second.startsWith("-")) dateTime = dateTime.minusSeconds(seconds); else/* w w w.j a va 2 s . c o m*/ dateTime = dateTime.withSecondOfMinute(seconds); } } return dateTime; }
From source file:com.gst.portfolio.loanaccount.domain.LoanAccountDomainServiceJpa.java
License:Apache License
@Override public Map<String, Object> foreCloseLoan(final Loan loan, final LocalDate foreClosureDate, final String noteText) { this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.LOAN_FORECLOSURE, constructEntityMap(BUSINESS_ENTITY.LOAN, loan)); MonetaryCurrency currency = loan.getCurrency(); LocalDateTime createdDate = DateUtils.getLocalDateTimeOfTenant(); final Map<String, Object> changes = new LinkedHashMap<>(); List<LoanTransaction> newTransactions = new ArrayList<>(); final List<Long> existingTransactionIds = new ArrayList<>(); final List<Long> existingReversedTransactionIds = new ArrayList<>(); existingTransactionIds.addAll(loan.findExistingTransactionIds()); existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds()); final ScheduleGeneratorDTO scheduleGeneratorDTO = null; AppUser appUser = getAppUserIfPresent(); final LoanRepaymentScheduleInstallment foreCloseDetail = loan.fetchLoanForeclosureDetail(foreClosureDate); if (loan.isPeriodicAccrualAccountingEnabledOnLoanProduct() && (loan.getAccruedTill() == null || !foreClosureDate.isEqual(loan.getAccruedTill()))) { loan.reverseAccrualsAfter(foreClosureDate); Money[] accruedReceivables = loan.getReceivableIncome(foreClosureDate); Money interestPortion = foreCloseDetail.getInterestCharged(currency).minus(accruedReceivables[0]); Money feePortion = foreCloseDetail.getFeeChargesCharged(currency).minus(accruedReceivables[1]); Money penaltyPortion = foreCloseDetail.getPenaltyChargesCharged(currency).minus(accruedReceivables[2]); Money total = interestPortion.plus(feePortion).plus(penaltyPortion); if (total.isGreaterThanZero()) { LoanTransaction accrualTransaction = LoanTransaction.accrueTransaction(loan, loan.getOffice(), foreClosureDate, total.getAmount(), interestPortion.getAmount(), feePortion.getAmount(), penaltyPortion.getAmount(), appUser); LocalDate fromDate = loan.getDisbursementDate(); if (loan.getAccruedTill() != null) { fromDate = loan.getAccruedTill(); }/*from w w w .ja v a 2s . c om*/ createdDate = createdDate.plusSeconds(1); newTransactions.add(accrualTransaction); loan.addLoanTransaction(accrualTransaction); Set<LoanChargePaidBy> accrualCharges = accrualTransaction.getLoanChargesPaid(); for (LoanCharge loanCharge : loan.charges()) { if (loanCharge.isActive() && !loanCharge.isPaid() && (loanCharge.isDueForCollectionFromAndUpToAndIncluding(fromDate, foreClosureDate) || loanCharge.isInstalmentFee())) { final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(accrualTransaction, loanCharge, loanCharge.getAmountOutstanding(currency).getAmount(), null); accrualCharges.add(loanChargePaidBy); } } } } Money interestPayable = foreCloseDetail.getInterestCharged(currency); Money feePayable = foreCloseDetail.getFeeChargesCharged(currency); Money penaltyPayable = foreCloseDetail.getPenaltyChargesCharged(currency); Money payPrincipal = foreCloseDetail.getPrincipal(currency); loan.updateInstallmentsPostDate(foreClosureDate); LoanTransaction payment = null; if (payPrincipal.plus(interestPayable).plus(feePayable).plus(penaltyPayable).isGreaterThanZero()) { final PaymentDetail paymentDetail = null; String externalId = null; final LocalDateTime currentDateTime = DateUtils.getLocalDateTimeOfTenant(); payment = LoanTransaction.repayment(loan.getOffice(), payPrincipal.plus(interestPayable).plus(feePayable).plus(penaltyPayable), paymentDetail, foreClosureDate, externalId, currentDateTime, appUser); createdDate = createdDate.plusSeconds(1); payment.updateCreatedDate(createdDate.toDate()); payment.updateLoan(loan); newTransactions.add(payment); } List<Long> transactionIds = new ArrayList<>(); final ChangedTransactionDetail changedTransactionDetail = loan.handleForeClosureTransactions(payment, defaultLoanLifecycleStateMachine(), scheduleGeneratorDTO, appUser); /*** * TODO Vishwas Batch save is giving me a * HibernateOptimisticLockingFailureException, looping and saving for * the time being, not a major issue for now as this loop is entered * only in edge cases (when a payment is made before the latest payment * recorded against the loan) ***/ for (LoanTransaction newTransaction : newTransactions) { saveLoanTransactionWithDataIntegrityViolationChecks(newTransaction); transactionIds.add(newTransaction.getId()); } changes.put("transactions", transactionIds); changes.put("eventAmount", payPrincipal.getAmount().negate()); if (changedTransactionDetail != null) { for (Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings() .entrySet()) { saveLoanTransactionWithDataIntegrityViolationChecks(mapEntry.getValue()); // update loan with references to the newly created transactions loan.getLoanTransactions().add(mapEntry.getValue()); updateLoanTransaction(mapEntry.getKey(), mapEntry.getValue()); } } saveAndFlushLoanWithDataIntegrityViolationChecks(loan); if (StringUtils.isNotBlank(noteText)) { changes.put("note", noteText); final Note note = Note.loanNote(loan, noteText); this.noteRepository.save(note); } postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, false); this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.LOAN_FORECLOSURE, constructEntityMap(BUSINESS_ENTITY.LOAN_TRANSACTION, payment)); return changes; }
From source file:de.avanux.smartapplianceenabler.appliance.Schedule.java
License:Open Source License
/** * Returns the current or next timeframe if the remaining time is greater than maximum running time; otherwise the next timeframe is returned. * @param now the time reference// w ww .j a v a 2s.com * @param schedules the list of timeframes to choose from (current timeframe has to be first) * @param onlyAlreadyStarted consider only timeframe intervals already started * @param onlySufficient if true consider timeframe already started only if time to interval end exceeds min running time * @return the next timeframe becoming valid or null */ public static TimeframeInterval getCurrentOrNextTimeframeInterval(LocalDateTime now, List<Schedule> schedules, boolean onlyAlreadyStarted, boolean onlySufficient) { if (schedules == null || schedules.size() == 0) { return null; } Map<Long, TimeframeInterval> startDelayOfTimeframeInterval = new TreeMap<>(); for (Schedule schedule : schedules) { Timeframe timeframe = schedule.getTimeframe(); timeframe.setSchedule(schedule); List<TimeframeInterval> timeframeIntervals = timeframe.getIntervals(now); for (TimeframeInterval timeframeInterval : timeframeIntervals) { Interval interval = timeframeInterval.getInterval(); if (interval.contains(now.toDateTime())) { // interval already started ... if (onlySufficient) { if (now.plusSeconds(schedule.getMaxRunningTime()).plusSeconds(additionalRunningTime) .isBefore(new LocalDateTime(interval.getEnd()))) { // ... with remaining running time sufficient return timeframeInterval; } } else { return timeframeInterval; } } else if (!onlyAlreadyStarted) { // interval starts in future startDelayOfTimeframeInterval.put(interval.getStartMillis() - now.toDateTime().getMillis(), timeframeInterval); } } } if (startDelayOfTimeframeInterval.size() > 0) { Long startDelay = startDelayOfTimeframeInterval.keySet().iterator().next(); return startDelayOfTimeframeInterval.get(startDelay); } return null; }
From source file:org.jtwig.functions.builtin.DateFunctions.java
License:Apache License
private Date modify(String modifyString, LocalDateTime localDateTime) throws FunctionException { LocalDateTime result;/*from w w w . ja v a 2 s . c o m*/ Matcher matcher = compile(MODIFY_PATTERN).matcher(modifyString); matcher.find(); int signal = 1; if (matcher.group(1).equals("-")) signal = -1; int val = Integer.valueOf(matcher.group(2)) * signal; String type = matcher.group(3).toLowerCase(); if (type.startsWith("day")) result = localDateTime.plusDays(val); else if (type.startsWith("month")) result = localDateTime.plusMonths(val); else if (type.startsWith("year")) result = localDateTime.plusYears(val); else if (type.startsWith("second")) result = localDateTime.plusSeconds(val); else if (type.startsWith("hour")) result = localDateTime.plusHours(val); else if (type.startsWith("minute")) result = localDateTime.plusMinutes(val); else throw new FunctionException("Unknown type " + matcher.group(3)); return result.toDate(); }