List of usage examples for org.joda.time LocalDate isBefore
public boolean isBefore(ReadablePartial partial)
From source file:module.siadap.domain.wrappers.PersonSiadapWrapper.java
License:Open Source License
@Atomic public void removeCustomEvaluator() { SiadapActionChangeValidatorEnum.EVALUATOR_CHANGE.validate(this); AccountabilityType evaluationRelation = getConfiguration().getEvaluationRelation(); for (Accountability accountability : getParentAccountabilityTypes(evaluationRelation)) { if (accountability.isActiveNow() && accountability.getChild() instanceof Person && accountability.getParent() instanceof Person) { // ok, so we have the acc. LocalDate dateToEndTheAcc = new LocalDate(); if (accountability.getBeginDate().getYear() == getYear()) { if (dateToEndTheAcc.isBefore(accountability.getBeginDate().plusDays(1))) { // then we actually have to 'delete' it accountability.delete(null); }/*w w w . ja va2 s . co m*/ dateToEndTheAcc = accountability.getBeginDate().plusDays(1); } else { // let's close it on the last day of the previous year dateToEndTheAcc = getConfiguration().getPreviousSiadapYearConfiguration().getLastDay(); } if (!accountability.isErased()) { accountability.setEndDate(dateToEndTheAcc); } } } }
From source file:net.cbtltd.rest.AbstractReservation.java
/** * Gets the search products.// w w w . j a v a 2 s. com * * @param locationid the locationid * @param fromdate the fromdate * @param todate the todate * @param pos the pos * @param currency the currency * @param terms the terms * @param xsl the xsl * @return the quotes */ public static synchronized SearchResponse getSearchProducts(String locationid, String fromdate, String todate, String productid, String guests, Boolean exactmatch, Boolean inquireonly, Boolean commission, String pos, String currency, Boolean terms, Boolean amenities, String page, String perpage, String xsl) { Date timestamp = new Date(); LocalDate currentDate = new LocalDate(); String message = "/search/quotes/" + locationid + "/" + fromdate + "/" + todate + "?pos=" + pos + "¤cy=" + currency + "&terms=" + terms + "&amenity" + amenities + "&page" + page + "&perpage" + perpage + "&xsl=" + xsl; //LOG.debug(message); SqlSession sqlSession = RazorServer.openSession(); SearchResponse response = new SearchResponse(); SearchQuotes result = null; List<Quote> filteredQuotes = null; List<Quote> listQuotes = null; Integer guestCount = 0; try { String[] locationids = locationid.split(","); if (!guests.isEmpty()) { guestCount = Integer.parseInt(guests); } LocalDate parsedFromDate = new LocalDate(Constants.parseDate(fromdate)); if (parsedFromDate.isBefore(currentDate)) { throw new Exception("Invalid from date parameter."); } if (locationids != null && locationids.length > 0) { ArrayList<String> itemsWithPrice = null; if (inquireonly) { itemsWithPrice = sqlSession.getMapper(ProductMapper.class) .inquireonlyidsbyparentlocationandprice(locationids[0], fromdate, todate); } else { itemsWithPrice = sqlSession.getMapper(ProductMapper.class) .idsbyparentlocationandprice(locationids[0], fromdate, todate); } ArrayList<String> itemsWithCollision = sqlSession.getMapper(ProductMapper.class) .idswithreservationcollision(locationids[0], fromdate, todate); if (itemsWithPrice != null) { itemsWithPrice.removeAll(itemsWithCollision); if (itemsWithPrice.size() > 0) { if (!productid.isEmpty()) { listQuotes = new ArrayList<Quote>(); if (itemsWithPrice.contains(productid)) { ArrayList<String> product = new ArrayList<String>(); product.add(productid); listQuotes = getProductsQuotes(sqlSession, pos, product, fromdate, todate, guestCount, exactmatch, currency, terms); } } else { listQuotes = getProductsQuotes(sqlSession, pos, itemsWithPrice, fromdate, todate, guestCount, exactmatch, currency, terms); } } if (listQuotes != null) { if (!page.isEmpty() && !perpage.isEmpty()) { Integer pageInt = Integer.parseInt(page); Integer perPageInt = Integer.parseInt(perpage); Integer offset = (pageInt - 1) * perPageInt; if (offset > listQuotes.size()) { throw new Exception("Invalid page number."); } Integer endOffset = ((listQuotes.size() - offset) > perPageInt) ? offset + perPageInt : listQuotes.size(); filteredQuotes = listQuotes.subList(offset, endOffset); } else { filteredQuotes = listQuotes; } Map<String, Quote> quotesMap = new HashMap<String, Quote>(); for (Quote item : filteredQuotes) { if (!commission) { item.setAgentCommission(null); item.setAgentCommissionValue(null); } quotesMap.put(item.getProductid(), item); item.getAttributes().add(""); } if (!quotesMap.keySet().isEmpty()) { if (amenities) { List<Relation> attributes = sqlSession.getMapper(RelationMapper.class) .headidsattributes(new ArrayList<String>(quotesMap.keySet())); if (attributes != null && !attributes.isEmpty()) { for (Relation relation : attributes) { String attribute = relation.getLineid(); Quote quote = quotesMap.get(relation.getHeadid()); if (attribute.startsWith("PCT") && StringUtils.isEmpty(quote.getProductClassType())) { quote.setProductClassType(attribute); } else { quote.getAttributes().add(attribute); } } } } else { List<Relation> productTypes = sqlSession.getMapper(RelationMapper.class) .productsclasstype(new ArrayList<String>(quotesMap.keySet())); if (productTypes != null && !productTypes.isEmpty()) { String attribute = productTypes.get(0).getLineid(); Quote quote = quotesMap.get(productTypes.get(0).getHeadid()); if (quote != null) { quote.setProductClassType(attribute); } } } } } result = new SearchQuotes(null, locationid, null, filteredQuotes, xsl); if (listQuotes != null) { result.setQuotesCount(String.valueOf(listQuotes.size())); } else { result.setQuotesCount("0"); } result.setQuotesPerPage(perpage); result.setPageNumber(page); } } } catch (Throwable x) { LOG.error(message + "\n" + x.getMessage()); result = new SearchQuotes(null, locationid, message + " " + x.getMessage(), null, xsl); response.setErrorMessage(x.getMessage()); } finally { sqlSession.close(); } LOG.debug(result); MonitorService.monitor(message, timestamp); response.setSearchQuotes(result); return response; }
From source file:net.jrkatz.minero.data.BudgetPeriodProvider.java
License:Open Source License
@NonNull public BudgetPeriod getCurrentBudgetPeriod(@NonNull final ProviderContext context, final long budgetId) throws ProviderException { BudgetPeriod budgetPeriod = getLatestBudgetPeriod(context, budgetId); //if this budgetPeriod is too old it may be necessary to create a new one or _several_ //new ones./*from w ww. ja va 2 s . com*/ final LocalDate now = LocalDate.now(); if (budgetPeriod == null) { final Budget budget = context.getBudgetProvider().getBudget(context, budgetId); final PeriodDefinition periodDefinition = budget.getPeriodDefinition(); final Period period = periodDefinition.periodForDate(now); budgetPeriod = createBudgetPeriod(context, budgetId, budget.getDistribution(), period); } else if (!now.isBefore(budgetPeriod.getPeriod().getEnd())) { final BudgetProvider bp = context.getBudgetProvider(); final Budget budget = bp.getBudget(context, budgetId); final PeriodDefinition periodDefinition = budget.getPeriodDefinition(); do { //add savings from previous period bp.setBudgetRunningTotal(context, budgetId, budgetPeriod.getRemaining()); //make subsequent period final Period nextPeriod = periodDefinition.periodForDate(budgetPeriod.getPeriod().getEnd()); budgetPeriod = createBudgetPeriod(context, budgetId, budget.getDistribution(), nextPeriod); } while (!now.isBefore(budgetPeriod.getPeriod().getEnd())); } return budgetPeriod; }
From source file:net.lshift.diffa.adapter.scanning.DateRangeConstraint.java
License:Apache License
public boolean contains(LocalDate value) { if (start != null && value.isBefore(start)) return false; if (end != null && value.isAfter(end)) return false; return true;/*w ww . j a v a 2 s.c o m*/ }
From source file:net.objectlab.kit.datecalc.joda.LocalDateCalculator.java
License:Apache License
@Override protected void checkBoundary(final LocalDate date) { final LocalDate early = getHolidayCalendar().getEarlyBoundary(); if (early != null && early.isAfter(date)) { throw new IndexOutOfBoundsException(date + " is before the early boundary " + early); }// w ww . j a v a2 s . com final LocalDate late = getHolidayCalendar().getLateBoundary(); if (late != null && late.isBefore(date)) { throw new IndexOutOfBoundsException(date + " is after the late boundary " + late); } }
From source file:net.objectlab.kit.datecalc.joda.LocalDateIMMDateCalculator.java
License:Apache License
private LocalDate calculateIMMMonth(final boolean requestNextIMM, final LocalDate startDate, final int month) { int monthOffset = 0; LocalDate date = startDate; switch (month) { case MARCH://w w w . j a v a 2s.c om case JUNE: case SEPTEMBER: case DECEMBER: final LocalDate immDate = calculate3rdWednesday(date); if (requestNextIMM && !date.isBefore(immDate)) { date = date.plusMonths(MONTHS_IN_QUARTER); } else if (!requestNextIMM && !date.isAfter(immDate)) { date = date.minusMonths(MONTHS_IN_QUARTER); } break; default: if (requestNextIMM) { monthOffset = (MONTH_IN_YEAR - month) % MONTHS_IN_QUARTER; date = date.plusMonths(monthOffset); } else { monthOffset = month % MONTHS_IN_QUARTER; date = date.minusMonths(monthOffset); } break; } return date; }
From source file:net.objectlab.kit.datecalc.joda.LocalDateIMMDateCalculator.java
License:Apache License
/** * Assumes that the month is correct, get the day for the 2rd wednesday. * * @param original//ww w . j a va 2s .c o m * the start date * @return the 3rd Wednesday of the month */ private LocalDate calculate3rdWednesday(final LocalDate original) { final LocalDate firstOfMonth = original.withDayOfMonth(1); LocalDate firstWed = firstOfMonth.withDayOfWeek(MONTHS_IN_QUARTER); if (firstWed.isBefore(firstOfMonth)) { firstWed = firstWed.plusWeeks(1); } return firstWed.plusWeeks(2); }
From source file:net.sourceforge.fenixedu.domain.phd.debts.PhdGratuityPaymentPeriod.java
License:Open Source License
public boolean contains(LocalDate date) { LocalDate start = new LocalDate(date.getYear(), getMonthStart(), getDayStart()); LocalDate end = new LocalDate(date.getYear(), getMonthEnd(), getDayEnd()); if ((date.equals(start) || date.isAfter(start)) && (date.equals(end) || date.isBefore(end))) { return true; } else {/* w w w .j av a 2 s . com*/ return false; } }
From source file:net.sourceforge.fenixedu.domain.phd.migration.common.ConversionUtilities.java
License:Open Source License
static public LocalDate parseDate(String value) { if (StringUtils.isEmpty(value)) { return null; }//from w w w . j a va 2s . com if (value.length() < 2) { return null; } LocalDate result = null; String normalizedValue = value; if (value.length() == "dMMyyyy".length()) { normalizedValue = "0".concat(value); } for (String pattern : CORRECT_DATE_PATTERNS) { try { result = DateTimeFormat.forPattern(pattern).parseDateTime(normalizedValue).toLocalDate(); } catch (IllegalArgumentException e) { continue; } if (result.isAfter(DateTimeFormat.forPattern("yyyy").parseDateTime("1920").toLocalDate()) && result.isBefore(DateTimeFormat.forPattern("yyy").parseDateTime("2020").toLocalDate())) { return result; } } throw new IncorrectDateFormatException(value); }
From source file:net.sourceforge.fenixedu.domain.student.Registration.java
License:Open Source License
final public RegistrationState getStateInDate(final LocalDate localDate) { final List<RegistrationState> sortedRegistrationStates = new ArrayList<RegistrationState>( getRegistrationStatesSet()); Collections.sort(sortedRegistrationStates, RegistrationState.DATE_COMPARATOR); for (ListIterator<RegistrationState> iterator = sortedRegistrationStates .listIterator(sortedRegistrationStates.size()); iterator.hasPrevious();) { RegistrationState registrationState = iterator.previous(); if (!localDate.isBefore(registrationState.getStateDate().toLocalDate())) { return registrationState; }/*from w w w .ja v a 2 s .c om*/ } return null; }