List of usage examples for org.joda.time LocalDate plusDays
public LocalDate plusDays(int days)
From source file:org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformServiceJpaRepositoryImpl.java
License:Mozilla Public License
public LoanOverdueDTO applyChargeToOverdueLoanInstallment(final Long loanId, final Long loanChargeId, final Integer periodNumber, final JsonCommand command, Loan loan, final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds) { boolean runInterestRecalculation = false; final Charge chargeDefinition = this.chargeRepository.findOneWithNotFoundDetection(loanChargeId); Collection<Integer> frequencyNumbers = loanChargeReadPlatformService .retrieveOverdueInstallmentChargeFrequencyNumber(loanId, chargeDefinition.getId(), periodNumber); Integer feeFrequency = chargeDefinition.feeFrequency(); final ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator(); Map<Integer, LocalDate> scheduleDates = new HashMap<>(); final Long penaltyWaitPeriodValue = this.configurationDomainService.retrievePenaltyWaitPeriod(); final Long penaltyPostingWaitPeriodValue = this.configurationDomainService .retrieveGraceOnPenaltyPostingPeriod(); final LocalDate dueDate = command.localDateValueOfParameterNamed("dueDate"); Long diff = penaltyWaitPeriodValue + 1 - penaltyPostingWaitPeriodValue; if (diff < 0) { diff = 0L;//from www. j a v a2 s. c o m } LocalDate startDate = dueDate.plusDays(penaltyWaitPeriodValue.intValue() + 1); Integer frequencyNunber = 1; if (feeFrequency == null) { scheduleDates.put(frequencyNunber++, startDate.minusDays(diff.intValue())); } else { while (new LocalDate().isAfter(startDate)) { scheduleDates.put(frequencyNunber++, startDate.minusDays(diff.intValue())); LocalDate scheduleDate = scheduledDateGenerator.getRepaymentPeriodDate( PeriodFrequencyType.fromInt(feeFrequency), chargeDefinition.feeInterval(), startDate, null, null); startDate = scheduleDate; } } for (Integer frequency : frequencyNumbers) { scheduleDates.remove(frequency); } LoanRepaymentScheduleInstallment installment = null; if (!scheduleDates.isEmpty()) { if (loan == null) { loan = this.loanAssembler.assembleFrom(loanId); checkClientOrGroupActive(loan); existingTransactionIds.addAll(loan.findExistingTransactionIds()); existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds()); } installment = loan.fetchRepaymentScheduleInstallment(periodNumber); } if (loan != null) { this.businessEventNotifierService.notifyBusinessEventToBeExecuted( BUSINESS_EVENTS.LOAN_APPLY_OVERDUE_CHARGE, constructEntityMap(BUSINESS_ENTITY.LOAN, loan)); for (Map.Entry<Integer, LocalDate> entry : scheduleDates.entrySet()) { final LoanCharge loanCharge = LoanCharge.createNewFromJson(loan, chargeDefinition, command, entry.getValue()); LoanOverdueInstallmentCharge overdueInstallmentCharge = new LoanOverdueInstallmentCharge(loanCharge, installment, entry.getKey()); loanCharge.updateOverdueInstallmentCharge(overdueInstallmentCharge); boolean isAppliedOnBackDate = addCharge(loan, chargeDefinition, loanCharge); runInterestRecalculation = runInterestRecalculation || isAppliedOnBackDate; } } return new LoanOverdueDTO(loan, runInterestRecalculation); }
From source file:org.neo4j.data.generator.domains.medicalrecords.encounters.EncounterSequenceGenerator.java
License:Open Source License
public List<Encounter> encountersSince(LocalDate dateOfBirth) { ArrayList<Encounter> encounters = new ArrayList<Encounter>(); LocalDate currentDate = dateOfBirth; LocalDate today = new LocalDate(); while (currentDate.isBefore(today)) { encounters.add(encounterGenerator.nextEncounter(currentDate)); currentDate = currentDate.plusDays((int) (Math.random() * 365 * MAX_YEARS_BETWEEN_ENCOUNTERS)); }//from www .j a v a 2 s.c om return encounters; }
From source file:org.onebusaway.admin.service.bundle.task.FixedRouteDataValidationTask.java
License:Apache License
private LocalDate getFirstDay(int dayOfWeek) { LocalDate today = LocalDate.now(); int old = today.getDayOfWeek(); if (dayOfWeek < old) { dayOfWeek += 7;/*from w w w . j a v a 2 s.c o m*/ } return today.plusDays(dayOfWeek - old); }
From source file:org.onebusaway.webapp.actions.admin.bundles.CompareBundlesAction.java
License:Apache License
private LocalDate getFirstDay(int dayOfWeek, LocalDate startDate) { int old = startDate.getDayOfWeek(); if (dayOfWeek < old) { dayOfWeek += 7;/*from w ww .j a v a 2 s . c o m*/ } return startDate.plusDays(dayOfWeek - old); }
From source file:org.smartdeveloperhub.harvesters.it.testing.generator.ProjectActivityGenerator.java
License:Apache License
private LocalDateTime createDueTo(final LocalDateTime dateTime) { LocalDate localDate = dateTime.toLocalDate().plusDays(1 + this.random.nextInt(15)); while (Utils.isWorkingDay(localDate)) { localDate = localDate.plusDays(1); }//from ww w. j av a2 s.c o m return localDate.toLocalDateTime(this.workDay.workingHour()); }
From source file:org.springframework.samples.petclinic.web.ResultController.java
License:Apache License
/** * * Complex algorith to find the winners /* w ww. jav a 2s . c o m*/ * */ private ArrayList<SumVotes> checkVoteResults() { //get votes Collection<Chooser> oCollection = this.clinicService.findChoices(); Iterator<Chooser> i = oCollection.iterator(); LocalDate dCurrentDate = new LocalDate();//DIA D HJ int nDiaSemana = dCurrentDate.getDayOfWeek(); LocalDate dFirstDayWeek = dCurrentDate.minusDays(nDiaSemana); LocalDate dFinalWeekDay = dFirstDayWeek.plusDays(6); //the week is starting on monday = 1 //sunday is 7 = friday is 5 ArrayList<VoteByDay> oKeepWeekDaysList = new ArrayList<VoteByDay>(); ArrayList<Vote> oInnerKeepWeekDaysList = new ArrayList<Vote>(); //run the list to keep the week day on one collection Chooser oneOptionChoosed = new Chooser(); while (i.hasNext()) { oneOptionChoosed = i.next(); //remove days outside of the week if (dFinalWeekDay.getDayOfYear() >= oneOptionChoosed.getPickedDate().getDayOfYear() && oneOptionChoosed.getPickedDate().getDayOfYear() >= dFirstDayWeek.getDayOfYear()) { Vote oVote = new Vote(); oVote.setRestaurantName(oneOptionChoosed.getRestaurant().getMainName()); oVote.setWeekDay(oneOptionChoosed.getPickedDate().getDayOfWeek()); oInnerKeepWeekDaysList.add(oVote); //print which data is in the week System.out.println("restaurant " + oneOptionChoosed.getRestaurant().getMainName() + " Data: " + oneOptionChoosed.getPickedDate().toString() + " user : " + oneOptionChoosed.getOwner().getLastName()); } //After today is not going to show //print database // System.out.println("restaurant " + oneOptionChoosed.getRestaurant().getMainName() + " Data: " + oneOptionChoosed.getPickedDate().toString() + // " user : " + oneOptionChoosed.getOwner().getLastName()); } boolean bSHouldInclude = false; //for to weekdays for (int ind = 1; ind <= 7; ind++) { VoteByDay oVoteByDay = new VoteByDay(); //runs over the total votes for (Vote oCurrentVote : oInnerKeepWeekDaysList) { if (ind == oCurrentVote.getWeekDay()) { bSHouldInclude = true; if (oVoteByDay.getComplexVote().containsKey(oCurrentVote.getRestaurantName())) { int nCurrentValue = oVoteByDay.getComplexVote().get(oCurrentVote.getRestaurantName()); nCurrentValue++; oVoteByDay.getComplexVote().put(oCurrentVote.getRestaurantName(), nCurrentValue); oVoteByDay.setWeekDay(ind); } else { oVoteByDay.getComplexVote().put(oCurrentVote.getRestaurantName(), 1); oVoteByDay.setWeekDay(ind); } } //dont need here, it will pass again for other day } if (bSHouldInclude) { oKeepWeekDaysList.add(oVoteByDay); bSHouldInclude = false; } } ArrayList<SumVotes> oKeepWinnersList = new ArrayList<SumVotes>(); boolean isDraw = false; //now prepare to show result //for (int indWeek = 1; indWeek < 8; indWeek++) for (VoteByDay oCheckWinnerVote : oKeepWeekDaysList) { Integer nCountVotes = 0; String sPossibleWinner = ""; String secondOptionRestaurant = ""; for (String key : oCheckWinnerVote.getComplexVote().keySet()) { //compare values int nTempValue = oCheckWinnerVote.getComplexVote().get(key); if (nTempValue > nCountVotes) { secondOptionRestaurant = sPossibleWinner; //used on repeated cases sPossibleWinner = key.toString(); nCountVotes = nTempValue; } else if (nTempValue == nCountVotes) { isDraw = true; sPossibleWinner += " & " + key.toString(); } else { secondOptionRestaurant = key.toString(); //used on repeated cases } } SumVotes oWinner = new SumVotes(); if (isDraw) { oWinner.setRestaurantName("Empate entre - " + sPossibleWinner); isDraw = false; } else { //test to not repeat restaurant for (SumVotes oCheckDuplicateWinnerVote : oKeepWinnersList) { if (sPossibleWinner.equals(oCheckDuplicateWinnerVote.getRestaurantName())) { System.out.println("Not allowed repeated restaurant on the week"); sPossibleWinner = secondOptionRestaurant; if (sPossibleWinner.length() < 1) { sPossibleWinner = "Restaurante repetido - dados insuficientes para indicar outro"; } } } oWinner.setRestaurantName(sPossibleWinner); } oWinner.setRestaurantName(sPossibleWinner); oWinner.setWeekDay(oCheckWinnerVote.getWeekDay()); oWinner.setTotalVotes(nCountVotes); oKeepWinnersList.add(oWinner); // if(isDraw) // System.out.println("possible empate"); // System.out.println("The winner is: " + sPossibleWinner + " With the following votes: " + nCountVotes.toString() + // " on the day " + oCheckWinnerVote.getWeekDay()); } //remove today data before 11am for (SumVotes oneWinnerVoteToDelete : oKeepWinnersList) { if (nDiaSemana == oneWinnerVoteToDelete.getWeekDay() && new DateTime().getHourOfDay() < 11) { oKeepWinnersList.remove(oneWinnerVoteToDelete); break; } } Integer nStartingWeekDay = dFirstDayWeek.getDayOfWeek(); //adjust week day to display for (SumVotes oneWinnerVote : oKeepWinnersList) { int nAdjustDay = 0; if (nStartingWeekDay > oneWinnerVote.getWeekDay()) { nAdjustDay = nStartingWeekDay - oneWinnerVote.getWeekDay() - 1; oneWinnerVote.setLunchTime(dFinalWeekDay.minusDays(nAdjustDay)); } else if (nStartingWeekDay == oneWinnerVote.getWeekDay()) { oneWinnerVote.setLunchTime(dFirstDayWeek); } else { nAdjustDay = nStartingWeekDay + oneWinnerVote.getWeekDay(); oneWinnerVote.setLunchTime(dFirstDayWeek.plusDays(nAdjustDay)); } } return oKeepWinnersList; }
From source file:org.surfnet.cruncher.repository.StatisticsRepositoryImpl.java
License:Apache License
/** * {@inheritDoc}/*from w ww . j ava2 s . c o m*/ */ @Override public List<LoginData> getLogins(final LocalDate start, final LocalDate end, final String idpEntityId, final String spEntityId) { final List<LoginData> result = new ArrayList<LoginData>(); NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(cruncherJdbcTemplate); String query = "select * from aggregated_log_logins " + "where " + "entryday >= :startDate AND " + "entryday <= :endDate AND " + "(:spEntityId IS NULL OR spentityid = :spEntityId) AND " + "(:idpEntityId IS NULL OR idpentityid = :idpEntityId) " + "order by idpentityid, spentityid, entryday "; Map<String, Object> parameterMap = getParameterMap(start, end, idpEntityId, spEntityId); namedJdbcTemplate.query(query, parameterMap, new RowMapper<Object>() { private Map<LocalDate, Integer> queryResult = new HashMap<LocalDate, Integer>(); private LoginData currentAggregate = null; @Override public Object mapRow(ResultSet rs, int row) throws SQLException { LoginData currentRow = getLoginDataFromRow(rs); /* * aggregate if sp/idp entityid differs from previous record * do not aggregate if on first record * if on last record, aggregate last entries */ if (!currentRow.equals(currentAggregate) && !rs.isFirst()) { //record is different, aggregate previous one and start fresh result.add(aggregateCurrentEntry(currentAggregate, start, end)); queryResult = new HashMap<LocalDate, Integer>(); } queryResult.put(new LocalDate(rs.getDate("entryday")), rs.getInt("entrycount")); currentAggregate = currentRow; if (rs.isLast()) { // aggregate last set result.add(aggregateCurrentEntry(currentAggregate, start, end)); } /* * This is kinda weird, but single row results are stored in * queryResult (hashmap) or aggregated in result (List<loginData) */ return null; } private LoginData aggregateCurrentEntry(final LoginData loginData, final LocalDate start, final LocalDate end) { LocalDate current = start; int total = 0; while (current.isBefore(end.plusDays(1))) { Integer count = queryResult.get(current); if (count == null) { loginData.getData().add(0); } else { loginData.getData().add(count); total += count; } current = current.plusDays(1); } loginData.setTotal(total); loginData.setPointStart(start.toDate().getTime()); loginData.setPointEnd(end.toDate().getTime()); loginData.setPointInterval(POINT_INTERVAL); return loginData; } private LoginData getLoginDataFromRow(ResultSet rs) throws SQLException { LoginData result = new LoginData(); result.setIdpEntityId(rs.getString("idpentityid")); result.setIdpname(rs.getString("idpentityname")); result.setSpEntityId(rs.getString("spentityid")); result.setSpName(rs.getString("spentityname")); return result; } }); return result; }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
protected CalendarItem[] buildDayItems() { LocalDate calendarFirstDay = getCalendarFirstDay(); LocalDate calendarLastDay = getCalendarLastDay(); LocalDate firstDayOfMonth = yearMonthDisplayed.toLocalDate(1); LocalDate lastDayOfMonth = yearMonthDisplayed.toLocalDate(1).dayOfMonth().withMaximumValue(); LocalDate today = LocalDate.now(); int numberOfDays = Days.daysBetween(calendarFirstDay, calendarLastDay).getDays() + 1; LocalDate date = calendarFirstDay; CalendarItem[] calendarItems = new CalendarItem[numberOfDays]; LocalDate currentValue = getLocalDate(); for (int i = 0; i < numberOfDays; i++, date = date.plusDays(1)) { calendarItems[i] = new CalendarItem(); calendarItems[i].setIndex(i);/* w w w . j a v a 2 s . c om*/ if (date.getMonthOfYear() == yearMonthDisplayed.getMonthOfYear()) { calendarItems[i].setRelativeDateIndex(date.getDayOfMonth()); } else { calendarItems[i].setRelativeDateIndex(-date.getDayOfMonth()); } String calendarItemContent = null; if (cellItemCustomizer != null) { calendarItemContent = cellItemCustomizer.renderDay(date, this); } // fallback to default value if (calendarItemContent == null) { calendarItemContent = Integer.toString(date.getDayOfMonth()); } calendarItems[i].setText(calendarItemContent); StringBuilder style = new StringBuilder(); if (date.equals(today)) { style.append("today "); } if (currentValue != null && date.equals(currentValue)) { style.append("selected "); } if (date.isBefore(firstDayOfMonth)) { style.append("previousmonth "); calendarItems[i].setEnabled(!isPreviousMonthDisabled()); } else if (date.isAfter(lastDayOfMonth)) { style.append("nextmonth "); calendarItems[i].setEnabled(!isNextMonthDisabled()); } else { style.append("currentmonth "); calendarItems[i].setEnabled(isDateEnabled(date)); } if (isWeekend(date)) { style.append("weekend "); } if (cellItemCustomizer != null) { String generatedStyle = cellItemCustomizer.getStyle(date, this); if (generatedStyle != null) { style.append(generatedStyle); style.append(" "); } String tooltip = cellItemCustomizer.getTooltip(date, this); if (tooltip != null) { calendarItems[i].setTooltip(tooltip); } } String computedStyle = style.toString(); if (!computedStyle.isEmpty()) { calendarItems[i].setStyle(computedStyle); } } return calendarItems; }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
/** * @return the last day of the calendar. As there are 7 columns displayed, if the last day of month is not in the * last column, we fill next column items with days of next month. *///from w w w .ja va 2s . c om private LocalDate getCalendarLastDay() { LocalDate lastDayOfMonth = yearMonthDisplayed.toLocalDate(1).dayOfMonth().withMaximumValue(); int calendarLastDayOfWeek = lastDayOfWeek; int numberOfDaysUntilLastDayOfWeek = (calendarLastDayOfWeek - lastDayOfMonth.getDayOfWeek() + 7) % 7; LocalDate lastDay = lastDayOfMonth.plusDays(numberOfDaysUntilLastDayOfWeek); if (isDisplayFixedNumberOfDayRows()) { // Always display 6 day rows int numberOfDays = Days.daysBetween(getCalendarFirstDay(), lastDay).getDays() + 1; if (numberOfDays / 7 < 5) { lastDay = lastDay.plusDays(14); } else if (numberOfDays / 7 < 6) { lastDay = lastDay.plusDays(7); } } return lastDay; }
From source file:org.zkoss.ganttz.timetracker.zoom.DetailFourTimeTrackerState.java
License:Open Source License
@Override protected Iterator<LocalDate> getPeriodsSecondLevelGenerator(LocalDate start) { return new LazyGenerator<LocalDate>(start) { @Override// w w w .j av a2 s . com protected LocalDate next(LocalDate last) { return last.getDayOfWeek() != 1 ? last.plusDays(getDaysUntilFirstDayNextWeek(last)) : last.plusWeeks(1); } }; }