List of usage examples for org.joda.time LocalDate minusDays
public LocalDate minusDays(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 w ww . j a va 2s.co 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.qi4j.sample.dcicargo.sample_a.infrastructure.wicket.form.DateTextFieldWithPicker.java
License:Apache License
public DateTextFieldWithPicker earliestDate(LocalDate newEarliestDate) { if (selectedDate != null && newEarliestDate.isAfter(selectedDate)) { throw new IllegalArgumentException("Earliest date can't be before selected day."); }//from w w w.j a va 2s . co m earliestDate = newEarliestDate; // Input field validation - date should be _after_ minimumDate (not the same) LocalDate minimumDate = newEarliestDate.minusDays(1); Date convertedMinimumDate = new DateTime(minimumDate.toDateTime(new LocalTime())).toDate(); add(DateValidator.minimum(convertedMinimumDate)); return this; }
From source file:org.solovyev.android.messenger.messages.Messages.java
License:Apache License
@Nonnull public static CharSequence getMessageTime(@Nonnull Message message) { final DateTimeZone localTimeZone = DateTimeZone.forTimeZone(TimeZone.getDefault()); final DateTime localSendDateTime = message.getLocalSendDateTime(); final LocalDate localSendDate = message.getLocalSendDate(); final LocalDate localToday = now(localTimeZone).toLocalDate(); final LocalDate localYesterday = localToday.minusDays(1); if (localSendDate.toDateTimeAtStartOfDay().compareTo(localToday.toDateTimeAtStartOfDay()) == 0) { // today// www . j a v a2 s . c om // print time return shortTime().print(localSendDateTime); } else if (localSendDate.toDateTimeAtStartOfDay().compareTo(localYesterday.toDateTimeAtStartOfDay()) == 0) { // yesterday return getApplication().getString(R.string.mpp_yesterday_at) + " " + shortTime().print(localSendDateTime); } else { // the days before yesterday return shortDate().print(localSendDateTime) + " " + getApplication().getString(R.string.mpp_at_time) + " " + shortTime().print(localSendDateTime); } }
From source file:org.springframework.samples.petclinic.web.ResultController.java
License:Apache License
/** * * Complex algorith to find the winners //from w w w .ja v a 2s . co 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.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
/** * @return the first day of the calendar. As there are 7 columns displayed, if the first day of month is not in the * first column, we fill previous column items with days of previous month. *//*from w w w . ja va 2 s .c om*/ private LocalDate getCalendarFirstDay() { LocalDate firstDayOfMonth = yearMonthDisplayed.toLocalDate(1); int calendarFirstDayOfWeek = firstDayOfWeek; int numberOfDaysSinceFirstDayOfWeek = (firstDayOfMonth.getDayOfWeek() - calendarFirstDayOfWeek + 7) % 7; return firstDayOfMonth.minusDays(numberOfDaysSinceFirstDayOfWeek); }
From source file:pt.ist.fenixedu.contracts.persistenceTierOracle.view.GiafEmployeeAssiduity.java
License:Open Source License
public static JsonObject readAssiduityOfEmployee(final User user, final LocalDate date, final User responsible) { final JsonObject result = new JsonObject(); result.addProperty("username", user.getUsername()); result.addProperty("name", user.getProfile().getDisplayName()); result.addProperty("avatarUrl", user.getProfile().getAvatarUrl()); final JsonArray records = new JsonArray(); result.add("assiduityRecords", records); GiafDbConnector.getInstance().executeQuery(new ResultSetConsumer() { @Override//w w w.ja v a 2 s. com public String query() { return "SELECT " + "a.ID_PICAGEM, " + "a.ID_EMPREGADO, " + "to_char(a.data,'YYYY-MM-DD'), " + "to_char(a.HORA, 'HH24:MI'), " + "a.OPERACAO, " + "a.TIPO " + "FROM MYGIAF_CASS_PICAGEM a" + (responsible == user ? " " : ", MYGIAF_V_RESP_SUBORDINADO b ") + "WHERE a.ID_EMPREGADO = ? AND (a.DATA = ? OR a.DATA = ?) " + (responsible == user ? "" : "AND a.ID_EMPREGADO = b.UTILIZADOR_NUM_EMP AND b.chefe_equipa_id = ? ") + "ORDER BY a.id_picagem"; } @Override public void prepare(final PreparedStatement statement) throws SQLException { final String giafNumber = convertIntoGiafNumber(getEmployeeNumber(user)); final LocalDate ld = (date == null ? new LocalDate() : date); statement.setString(1, giafNumber); statement.setString(2, ld.toString("yyyy-MM-dd")); statement.setString(3, ld.minusDays(1).toString("yyyy-MM-dd")); if (responsible != user) { statement.setString(4, responsible.getUsername().toUpperCase()); } } @Override public void accept(final ResultSet resultSet) throws SQLException { final JsonObject view = new JsonObject(); view.addProperty("moment", resultSet.getString(3) + " " + resultSet.getString(4)); view.addProperty("operation", resultSet.getString(5)); records.add(view); } }); return result; }
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportEmployeeUnitsFromGiaf.java
License:Open Source License
private List<Modification> importIt(PersistentSuportGiaf oracleConnection, GiafMetadata metadata, LocalDate today, String query, AccountabilityTypeEnum accountabilityTypeEnum, PrintWriter log, Logger logger) throws SQLException { List<Modification> modifications = new ArrayList<>(); PreparedStatement preparedStatement = oracleConnection.prepareStatement(query); ResultSet result = preparedStatement.executeQuery(); while (result.next()) { String employeeNumber = result.getString("emp_num"); Employee employee = metadata.getEmployee(employeeNumber, logger); if (employee == null) { log.println(accountabilityTypeEnum.getName() + ". No existe funcionrio. Nmero: " + employeeNumber);//from ww w. j av a 2 s. co m continue; } Integer costCenterCode = 0; try { costCenterCode = result.getInt("cc"); } catch (SQLException e) { log.println(accountabilityTypeEnum.getName() + ". CC invlido. Nmero: " + employeeNumber); continue; } Unit unit = costCenterCode.intValue() == 0 ? null : Unit.readByCostCenterCode(costCenterCode); String ccDateString = result.getString("cc_date"); LocalDate beginDate = today; if (!Strings.isNullOrEmpty(ccDateString)) { beginDate = new LocalDate(Timestamp.valueOf(ccDateString)); } if (unit != null || costCenterCode.intValue() == 0) { if (employee.getPerson().getPersonProfessionalData() != null) { GiafProfessionalData giafProfessionalDataByGiafPersonIdentification = employee.getPerson() .getPersonProfessionalData() .getGiafProfessionalDataByGiafPersonIdentification(employeeNumber); ContractSituation contractSituation = giafProfessionalDataByGiafPersonIdentification .getContractSituation(); if (contractSituation != null) { LocalDate endDate = null; if (contractSituation.getEndSituation()) { PersonContractSituation personContractSituation = getOtherValidPersonContractSituation( giafProfessionalDataByGiafPersonIdentification); if (personContractSituation != null) { contractSituation = personContractSituation.getContractSituation(); endDate = personContractSituation.getEndDate(); } else { endDate = giafProfessionalDataByGiafPersonIdentification.getContractSituationDate(); } } Contract workingContractOnDate = getLastContractByContractType(employee, accountabilityTypeEnum, new YearMonthDay(beginDate), endDate == null ? null : new YearMonthDay(endDate)); if (workingContractOnDate != null) { if (unit != null && endDate == null) { if (!workingContractOnDate.getUnit().equals(unit)) { modifications.addAll(createEmployeeContract(employee, new YearMonthDay(beginDate), null, unit, accountabilityTypeEnum, workingContractOnDate, log, logger)); } else if (!workingContractOnDate.getBeginDate().equals(beginDate) && !Strings.isNullOrEmpty(ccDateString)) { modifications.add(changeEmployeeContractDates(accountabilityTypeEnum, new YearMonthDay(beginDate), workingContractOnDate, log, logger)); } else if (workingContractOnDate.getEndDate() != null && contractSituation != null && giafProfessionalDataByGiafPersonIdentification .getContractSituationDate() != null) { log.println(accountabilityTypeEnum.getName() + ". Contrato do Funcionrio:" + employeeNumber + " Voltou a abrir na mesma unidade :" + giafProfessionalDataByGiafPersonIdentification .getContractSituationDate()); modifications.addAll(createEmployeeContract(employee, new YearMonthDay(giafProfessionalDataByGiafPersonIdentification .getContractSituationDate()), null, unit, accountabilityTypeEnum, null, log, logger)); } else { log.println(accountabilityTypeEnum.getName() + ". No h alteraes para o funcionrio:" + employeeNumber); } } else if (endDate != null) { // terminou o contrato corrente modifications .add(closeCurrentContract(accountabilityTypeEnum, workingContractOnDate, new YearMonthDay(endDate.minusDays(1)), log, logger)); } } else { if (unit != null && endDate == null) { // contrato novo modifications.addAll(createEmployeeContract(employee, new YearMonthDay(beginDate), null, unit, accountabilityTypeEnum, null, log, logger)); } else { // j tinha terminado o contrato e j // terminou // tb do nosso lado // log.println(accountabilityTypeEnum.getName() // + ". Contrato terminado na unidade " // + unit.getName() + " para o funcionrio:" // + employeeNumber + " (no fez nada)"); } } } else { log.println("ERRO... no tem situao no GIAF " + employeeNumber); Contract currentWorkingContract = employee .getCurrentContractByContractType(accountabilityTypeEnum); if (currentWorkingContract != null) { LocalDate endDate = today.minusDays(1); closeCurrentContract(accountabilityTypeEnum, currentWorkingContract, new YearMonthDay(endDate), log, logger); log.println(accountabilityTypeEnum.getName() + ". No no tem contrato no GIAF, e terminamos no Fnix: " + employeeNumber); } else { log.println(accountabilityTypeEnum.getName() + ". No no tem contrato no GIAF, nem no fnix: " + employeeNumber); } } } else { log.println("No tem employeeProfessionalData. Funcionario: " + employeeNumber); } } else { log.println(accountabilityTypeEnum.getName() + ". No existe unidade: " + costCenterCode + " para o funcionario: " + employeeNumber); } } result.close(); preparedStatement.close(); return modifications; }
From source file:ru.codemine.ccms.service.SalesService.java
License:Open Source License
public List<Sales> getAllSalesFromMetaList(List<SalesMeta> smList, LocalDate startDate, LocalDate endDate) { List<Sales> result = new ArrayList<>(); for (SalesMeta sm : smList) { for (Sales s : sm.getSales()) { if (s.getDate().isAfter(startDate.minusDays(1)) && s.getDate().isBefore(endDate.plusDays(1))) result.add(s);// w w w .ja v a 2s . c o m } } return result; }