List of usage examples for org.joda.time LocalDate withDayOfMonth
public LocalDate withDayOfMonth(int dayOfMonth)
From source file:com.axelor.apps.base.service.scheduler.SchedulerService.java
License:Open Source License
/** * Obtient le prochain jour du mois partir d'une date * * @param localDate/*from w w w . j av a 2s . c o m*/ * Date de rfrence * @param dayMonthly * Jour du mois * * @return LocalDate * Date correspondant au prochain jour du mois */ public LocalDate getNextDayMonth(LocalDate localDate, int dayMonthly) { LocalDate date = null; int start = localDate.dayOfMonth().getMinimumValue(); int end = localDate.dayOfMonth().getMaximumValue(); if (localDate.dayOfMonth().get() <= dayMonthly) { if (start <= dayMonthly && dayMonthly <= end) date = localDate.withDayOfMonth(dayMonthly); else if (dayMonthly < start) date = localDate.dayOfMonth().withMinimumValue(); else if (dayMonthly > end) date = localDate.dayOfMonth().withMaximumValue(); } else { int startNext = localDate.plusMonths(1).dayOfMonth().getMinimumValue(); int endNext = localDate.plusMonths(1).dayOfMonth().getMaximumValue(); if (startNext <= dayMonthly && dayMonthly <= endNext) date = localDate.plusMonths(1).withDayOfMonth(dayMonthly); else if (dayMonthly < startNext) date = localDate.plusMonths(1).dayOfMonth().withMinimumValue(); else if (dayMonthly > endNext) date = localDate.plusMonths(1).dayOfMonth().withMaximumValue(); } return date; }
From source file:com.gst.portfolio.account.service.StandingInstructionWritePlatformServiceImpl.java
License:Apache License
@Override @CronTarget(jobName = JobName.EXECUTE_STANDING_INSTRUCTIONS) public void executeStandingInstructions() throws JobExecutionException { Collection<StandingInstructionData> instructionDatas = this.standingInstructionReadPlatformService .retrieveAll(StandingInstructionStatus.ACTIVE.getValue()); final StringBuilder sb = new StringBuilder(); for (StandingInstructionData data : instructionDatas) { boolean isDueForTransfer = false; AccountTransferRecurrenceType recurrenceType = data.recurrenceType(); StandingInstructionType instructionType = data.instructionType(); LocalDate transactionDate = new LocalDate(); if (recurrenceType.isPeriodicRecurrence()) { final ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator(); PeriodFrequencyType frequencyType = data.recurrenceFrequency(); LocalDate startDate = data.validFrom(); if (frequencyType.isMonthly()) { startDate = startDate.withDayOfMonth(data.recurrenceOnDay()); if (startDate.isBefore(data.validFrom())) { startDate = startDate.plusMonths(1); }/*from w ww. j a v a 2s.co m*/ } else if (frequencyType.isYearly()) { startDate = startDate.withDayOfMonth(data.recurrenceOnDay()) .withMonthOfYear(data.recurrenceOnMonth()); if (startDate.isBefore(data.validFrom())) { startDate = startDate.plusYears(1); } } isDueForTransfer = scheduledDateGenerator.isDateFallsInSchedule(frequencyType, data.recurrenceInterval(), startDate, transactionDate); } BigDecimal transactionAmount = data.amount(); if (data.toAccountType().isLoanAccount() && (recurrenceType.isDuesRecurrence() || (isDueForTransfer && instructionType.isDuesAmoutTransfer()))) { StandingInstructionDuesData standingInstructionDuesData = this.standingInstructionReadPlatformService .retriveLoanDuesData(data.toAccount().accountId()); if (data.instructionType().isDuesAmoutTransfer()) { transactionAmount = standingInstructionDuesData.totalDueAmount(); } if (recurrenceType.isDuesRecurrence()) { isDueForTransfer = new LocalDate().equals(standingInstructionDuesData.dueDate()); } } if (isDueForTransfer && transactionAmount != null && transactionAmount.compareTo(BigDecimal.ZERO) > 0) { final SavingsAccount fromSavingsAccount = null; final boolean isRegularTransaction = true; final boolean isExceptionForBalanceCheck = false; AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, transactionAmount, data.fromAccountType(), data.toAccountType(), data.fromAccount().accountId(), data.toAccount().accountId(), data.name() + " Standing instruction trasfer ", null, null, null, null, data.toTransferType(), null, null, data.transferType().getValue(), null, null, null, null, null, fromSavingsAccount, isRegularTransaction, isExceptionForBalanceCheck); final boolean transferCompleted = transferAmount(sb, accountTransferDTO, data.getId()); if (transferCompleted) { final String updateQuery = "UPDATE m_account_transfer_standing_instructions SET last_run_date = ? where id = ?"; this.jdbcTemplate.update(updateQuery, transactionDate.toDate(), data.getId()); } } } if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); } }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java
License:Apache License
private LocalDate adjustToNthWeekDay(LocalDate dueRepaymentPeriodDate, int nthDay, int dayOfWeek) { // adjust date to start of month dueRepaymentPeriodDate = dueRepaymentPeriodDate.withDayOfMonth(1); // adjust date to next week if current day is past specified day of // week.// w w w.j a va2 s. co m if (dueRepaymentPeriodDate.getDayOfWeek() > dayOfWeek) { dueRepaymentPeriodDate = dueRepaymentPeriodDate.plusWeeks(1); } // adjust date to specified date of week dueRepaymentPeriodDate = dueRepaymentPeriodDate.withDayOfWeek(dayOfWeek); // adjust to specified nth week day dueRepaymentPeriodDate = dueRepaymentPeriodDate.plusWeeks(nthDay - 1); return dueRepaymentPeriodDate; }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
private LocalDate setDayOfMonth(LocalDate nextDueLocalDate) { int maxDayOfMonth = nextDueLocalDate.dayOfMonth().withMaximumValue().getDayOfMonth(); int newDayOfMonth = (this.feeOnDay.intValue() < maxDayOfMonth) ? this.feeOnDay.intValue() : maxDayOfMonth; nextDueLocalDate = nextDueLocalDate.withDayOfMonth(newDayOfMonth); return nextDueLocalDate; }
From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
protected static LocalDate parse(final int nYear, final FixedWeekdayInMonth aFixedWeekdayInMonth) { LocalDate aDate = PDTFactory.createLocalDate(nYear, XMLUtil.getMonth(aFixedWeekdayInMonth.getMonth()), 1); int nDirection = 1; if (aFixedWeekdayInMonth.getWhich() == Which.LAST) { aDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue()); nDirection = -1;/*from ww w. j av a 2s . co m*/ } final int nWeekDay = XMLUtil.getWeekday(aFixedWeekdayInMonth.getWeekday()); while (aDate.getDayOfWeek() != nWeekDay) { aDate = aDate.plusDays(nDirection); } switch (aFixedWeekdayInMonth.getWhich()) { case FIRST: break; case SECOND: aDate = aDate.plusDays(7); break; case THIRD: aDate = aDate.plusDays(14); break; case FOURTH: aDate = aDate.plusDays(21); break; case LAST: break; } return aDate; }
From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
/** * Parses the {@link FixedWeekdayInMonth}. * * @param year/*w ww . j a v a 2 s. co m*/ * the year * @param fwm * the fwm * @return the local date */ protected LocalDate parse(int year, FixedWeekdayInMonth fwm) { LocalDate date = calendarUtil.create(year, xmlUtil.getMonth(fwm.getMonth()), 1); int direction = 1; if (Which.LAST.equals(fwm.getWhich())) { date = date.withDayOfMonth(date.dayOfMonth().getMaximumValue()); direction = -1; } date = moveToNextRequestedWeekdayByDirection(fwm, date, direction); date = moveNumberOfRequestedWeeks(fwm, date); return date; }
From source file:com.mars.test.jodatime.Mars_App.java
public static void main(String[] args) { // LocalDate , TimeZone LocalDate dt = new LocalDate(); // 1.?1~31/*from www . java 2 s. c om*/ log.info("1.?" + dt.withDayOfMonth(1).toString(pattern) + " ~ " + dt.dayOfMonth().withMaximumValue().toString(pattern)); // 2.?26~25(????) log.info("2.?" + dt.minusMonths(1).withDayOfMonth(26).toString(pattern) + " ~ " + dt.withDayOfMonth(25).toString(pattern)); // 3.??? LocalDate date2 = dt.withDayOfMonth(5); if (date2.getDayOfWeek() == DateTimeConstants.SATURDAY || date2.getDayOfWeek() == DateTimeConstants.SUNDAY) { date2 = date2.plusWeeks(1).withDayOfWeek(1); } log.info("3." + date2.toString(pattern)); LocalDate date3 = dt.plusMonths(1).withDayOfMonth(5); if (date3.getDayOfWeek() >= 6) { date3 = date3.plusWeeks(1).withDayOfWeek(1); } log.info("4.2014/7" + date3.toString(pattern)); }
From source file:com.squid.kraken.v4.api.core.EngineUtils.java
License:Open Source License
/** * Convert the facet value into a date. * If the value start with '=', it is expected to be a Expression, in which case we'll try to resolve it to a Date constant. * @param ctx// w ww . j a v a 2s . c o m * @param index * @param lower * @param value * @param compareFromInterval * @return * @throws ParseException * @throws ScopeException * @throws ComputingException */ public Date convertToDate(Universe universe, DimensionIndex index, Bound bound, String value, IntervalleObject compareFromInterval) throws ParseException, ScopeException, ComputingException { if (value.equals("")) { return null; } else if (value.startsWith("__")) { // // support hard-coded shortcuts if (value.toUpperCase().startsWith("__COMPARE_TO_")) { // for compareTo if (compareFromInterval == null) { // invalid compare_to selection... return null; } if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_PERIOD")) { LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime()); if (bound == Bound.UPPER) { LocalDate date = localLower.minusDays(1); return date.toDate(); } else { LocalDate localUpper = new LocalDate( ((Date) compareFromInterval.getUpperBound()).getTime()); Days days = Days.daysBetween(localLower, localUpper); LocalDate date = localLower.minusDays(1 + days.getDays()); return date.toDate(); } } if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_MONTH")) { LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime()); LocalDate compareLower = localLower.minusMonths(1); if (bound == Bound.LOWER) { return compareLower.toDate(); } else { LocalDate localUpper = new LocalDate( ((Date) compareFromInterval.getUpperBound()).getTime()); Days days = Days.daysBetween(localLower, localUpper); LocalDate compareUpper = compareLower.plusDays(days.getDays()); return compareUpper.toDate(); } } if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_YEAR")) { LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime()); LocalDate compareLower = localLower.minusYears(1); if (bound == Bound.LOWER) { return compareLower.toDate(); } else { LocalDate localUpper = new LocalDate( ((Date) compareFromInterval.getUpperBound()).getTime()); Days days = Days.daysBetween(localLower, localUpper); LocalDate compareUpper = compareLower.plusDays(days.getDays()); return compareUpper.toDate(); } } } else { // for regular // get MIN, MAX first Intervalle range = null; if (index.getDimension().getType() == Type.CONTINUOUS) { if (index.getStatus() == Status.DONE) { List<DimensionMember> members = index.getMembers(); if (!members.isEmpty()) { DimensionMember member = members.get(0); Object object = member.getID(); if (object instanceof Intervalle) { range = (Intervalle) object; } } } else { try { DomainHierarchy hierarchy = universe .getDomainHierarchy(index.getAxis().getParent().getDomain()); hierarchy.isDone(index, null); } catch (ComputingException | InterruptedException | ExecutionException | TimeoutException e) { throw new ComputingException("failed to retrieve period interval"); } } } if (range == null) { range = IntervalleObject.createInterval(new Date(), new Date()); } if (value.equalsIgnoreCase("__ALL")) { if (index.getDimension().getType() != Type.CONTINUOUS) { return null; } if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { return (Date) range.getLowerBound(); } } if (value.equalsIgnoreCase("__LAST_DAY")) { if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { return (Date) range.getUpperBound(); } } if (value.equalsIgnoreCase("__LAST_7_DAYS")) { if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.minusDays(6);// 6+1 return date.toDate(); } } if (value.equalsIgnoreCase("__CURRENT_MONTH")) { if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withDayOfMonth(1); return date.toDate(); } } if (value.equalsIgnoreCase("__CURRENT_YEAR")) { if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1); return date.toDate(); } } if (value.equalsIgnoreCase("__PREVIOUS_MONTH")) {// the previous complete month if (bound == Bound.UPPER) { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withDayOfMonth(1).minusDays(1); return date.toDate(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withDayOfMonth(1).minusMonths(1); return date.toDate(); } } if (value.equalsIgnoreCase("__PREVIOUS_YEAR")) {// the previous complete month if (bound == Bound.UPPER) { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusDays(1); return date.toDate(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusYears(1); return date.toDate(); } } } throw new ScopeException("undefined facet expression alias: " + value); } else if (value.startsWith("=")) { // if the value starts by equal token, this is a formula that can be // evaluated try { String expr = value.substring(1); // check if the index content is available or wait for it DomainHierarchy hierarchy = universe.getDomainHierarchy(index.getAxis().getParent().getDomain(), true); hierarchy.isDone(index, null); // evaluate the expression Object defaultValue = evaluateExpression(universe, index, expr, compareFromInterval); // check we can use it if (defaultValue == null) { //throw new ScopeException("unable to parse the facet expression as a constant: " + expr); // T1769: it's ok to return null return null; } if (!(defaultValue instanceof Date)) { throw new ScopeException("unable to parse the facet expression as a date: " + expr); } // ok, it's a date return (Date) defaultValue; } catch (ComputingException | InterruptedException | ExecutionException | TimeoutException e) { throw new ComputingException("failed to retrieve period interval"); } } else { Date date = ServiceUtils.getInstance().toDate(value); if (bound == Bound.UPPER && !index.getAxis().getDefinitionSafe().getImageDomain().isInstanceOf(IDomain.TIME)) { // clear the timestamp return new LocalDate(date.getTime()).toDate(); } else { return date; } } }
From source file:com.stagecents.pay.domain.PayCycle.java
License:Open Source License
public LocalDate getCycleEnd(LocalDate cycleStart) { LocalDate result = null;/*from w ww . j a v a 2 s .c om*/ if (frequency.equals(Frequency.W)) { result = cycleStart.plusDays(6); } else if (frequency.equals(Frequency.F)) { result = cycleStart.plusDays(13); } else if (frequency.equals(Frequency.SM)) { result = (cycleStart.getDayOfMonth() == 1) ? cycleStart.withDayOfMonth(15) : cycleStart.dayOfMonth().withMaximumValue(); } else if (frequency.equals(Frequency.CM)) { result = cycleStart.dayOfMonth().withMaximumValue(); } else if (frequency.equals(Frequency.Q)) { result = cycleStart.plusMonths(2).dayOfMonth().withMaximumValue(); } return result; }
From source file:de.appsolve.padelcampus.controller.RootController.java
private void addPageEntries(Module module, ModelAndView mav) { List<PageEntry> pageEntries = pageEntryDAO.findByModule(module); mav.addObject("PageEntries", pageEntries); for (PageEntry pageEntry : pageEntries) { if (pageEntry.getShowEventCalendar()) { List<Event> events = eventDAO.findAllActiveStartingWith(LocalDate.now()); List<JSEvent> jsEvents = new ArrayList<>(); for (Event event : events) { jsEvents.add(new JSEvent(event)); }/*from w w w . j a v a2s . c o m*/ try { mav.addObject("Events", objectMapper.writeValueAsString(jsEvents)); } catch (JsonProcessingException e) { LOG.error(e); } break; } if (pageEntry.getShowEventOverview()) { LocalDate today = LocalDate.now(); List<Event> currentEvents = eventDAO.findAllActiveStartingWith(today); Map<Integer, ArrayList<Event>> eventMap = new TreeMap<>(); for (Event event : currentEvents) { int monthOfYear = event.getStartDate().getMonthOfYear() - 1; if (eventMap.get(monthOfYear) == null) { eventMap.put(monthOfYear, new ArrayList<>()); } eventMap.get(monthOfYear).add(event); } // add passed events of current month AFTER upcoming events of current month LocalDate firstOfMonth = today.withDayOfMonth(1); int currentMonth = firstOfMonth.getMonthOfYear() - 1; List<Event> passedEvents = eventDAO.findAllActiveStartingWithEndingBefore(firstOfMonth, today); if (passedEvents != null && !passedEvents.isEmpty()) { if (eventMap.get(currentMonth) == null) { eventMap.put(currentMonth, new ArrayList<>()); } eventMap.get(currentMonth).addAll(passedEvents); } mav.addObject("EventMap", eventMap); mav.addObject("Today", today); } } }