List of usage examples for org.joda.time LocalDate isAfter
public boolean isAfter(ReadablePartial partial)
From source file:de.jollyday.parser.impl.FixedWeekdayBetweenFixedParser.java
License:Apache License
/** * {@inheritDoc}//w w w. ja v a 2 s . com * * Parses the provided configuration and creates holidays for the provided * year. */ @Override public void parse(int year, Set<Holiday> holidays, final Holidays config) { for (FixedWeekdayBetweenFixed fwm : config.getFixedWeekdayBetweenFixed()) { if (!isValid(fwm, year)) { continue; } LocalDate from = calendarUtil.create(year, fwm.getFrom()); LocalDate to = calendarUtil.create(year, fwm.getTo()); LocalDate result = null; for (; !from.isAfter(to);) { if (from.getDayOfWeek() == xmlUtil.getWeekday(fwm.getWeekday())) { result = from; break; } from = from.plusDays(1); } if (result != null) { HolidayType type = xmlUtil.getType(fwm.getLocalizedType()); holidays.add(new Holiday(result, fwm.getDescriptionPropertiesKey(), type)); } } }
From source file:de.phoenix.rs.entity.PhoenixDetails.java
License:Open Source License
/** * Constructor for client/server/*from w w w.jav a2 s. c o m*/ * * @param room * The room where the event is happening * @param weekday * The day of the week * @param startTime * The time when the events starts * @param interval * The interval of the event. Will be replaced by an enum * @param startDate * The start date of the event(before this date, the event does * not exist!) * @param endDate * The end date of the event(after this date, the event does not * exist!) */ public PhoenixDetails(String room, Weekday weekday, LocalTime startTime, LocalTime endTime, Period interval, LocalDate startDate, LocalDate endDate) { this.room = room; this.weekday = weekday; this.startTime = startTime; this.endTime = endTime; this.interval = interval; this.startDate = startDate; this.endDate = endDate; if (startTime.isAfter(endTime)) throw new InvalidParameterException("StartTime is after EndTime!"); if (startDate.isAfter(endDate)) throw new InvalidParameterException("StartDate is after EndDate!"); }
From source file:dom.simple.AlumnoRepositorio.java
License:Open Source License
public String validateCreate(String nombre, String apellido, E_sexo sexo, int dni, LocalDate nacimiento, E_nacionalidad nacionalidad, E_localidades localidad, String calle, int numero, String piso, String departamento, String telefono) { List<Alumno> dniAlumno = container .allMatches((new QueryDefault<Alumno>(Alumno.class, "findByDni", "dni", dni))); if (!dniAlumno.isEmpty()) { return "El nmero de dni ya existe"; }/*from w ww. ja v a 2s . c om*/ if (nacimiento.isAfter(LocalDate.now())) { return "La fecha de nacimiento debe ser menor al da actual"; } return null; }
From source file:domainapp.app.services.menu.InstellingenMenu.java
License:Apache License
public String validateExportBlobs(final LocalDate before, final boolean onlyExportNoDelete) { LocalDate threshold = clockService.now().minusMonths(6); if (!onlyExportNoDelete && before.isAfter(threshold)) { return "Kies een datum die langer dan een half jaar geleden is"; }/*from ww w. jav a 2s.c o m*/ return null; }
From source file:energy.usef.agr.service.business.AgrValidationBusinessService.java
License:Apache License
/** * FlexOrders should only be accepted if they refer to a future period or contain future PTU's with a power value != 0. * * @param order is the {@link FlexOrder} to validate * @throws BusinessValidationException//from w ww .ja v a 2 s.co m */ public void validateFlexOrderTiming(FlexOrder order) throws BusinessValidationException { Integer ptuDuration = config.getIntegerProperty(ConfigParam.PTU_DURATION); LocalDateTime currentDateTime = DateTimeUtil.getCurrentDateTime(); LocalDate currentPeriod = DateTimeUtil.getCurrentDate(); int numberOfPtus = PtuUtil.getNumberOfPtusPerDay(currentPeriod, ptuDuration); int currentPtu = PtuUtil.getPtuIndex(currentDateTime, ptuDuration); // No further checking if the flex order is entirely in the future if (currentPeriod.isBefore(order.getPeriod())) { return; } // Do not accept the flex order if it is entirely in the past if (currentPeriod.isAfter(order.getPeriod())) { LOGGER.warn("Flex offer not acceptable, period is in the past. "); throw new BusinessValidationException(AgrBusinessError.FLEX_ORDER_PERIOD_IN_THE_PAST, order); } // Only accept flex order that have at least one future PTU with a power value <> 0 List<PTU> orderPTUs = order.getPTU(); orderPTUs = PtuListConverter.normalize(orderPTUs); boolean valid = false; for (int i = currentPtu - 1; i < numberOfPtus && !valid; i++) { if (orderPTUs.get(i).getPower().compareTo(BigInteger.ZERO) != 0) { valid = true; } } if (!valid) { LOGGER.warn("Flex order not acceptable, no future PTU's with non-zero power values. "); throw new BusinessValidationException(AgrBusinessError.FLEX_ORDER_WITHOUT_NON_ZERO_FUTURE_POWER, order); } }
From source file:energy.usef.agr.workflow.step.AgrReOptimizePortfolioStub.java
License:Apache License
private List<DeviceMessageDto> createDeviceMessages( Map<String, List<ConnectionPortfolioDto>> connectionPortfolioPerConnectionGroup, Map<String, List<UdiEventDto>> udiEventsPerUdi, Map<String, Map<Integer, BigInteger>> targetPowerPerPtuPerConnectionGroup, LocalDate ptuDate, int ptuDuration, int currentPtuIndex) { List<DeviceMessageDto> deviceMessageDtoList = new ArrayList<>(); boolean isAfterToday = ptuDate.isAfter(DateTimeUtil.getCurrentDate()); connectionPortfolioPerConnectionGroup .forEach((connectionGroupId, connectionPortfolioList) -> targetPowerPerPtuPerConnectionGroup .get(connectionGroupId).entrySet().stream() .filter(entry -> isAfterToday || entry.getKey() >= currentPtuIndex).forEach(entry -> { int ptuIndex = entry.getKey(); BigInteger targetPower = entry.getValue(); List<UdiPortfolioDto> udis = connectionPortfolioList.stream() .map(ConnectionPortfolioDto::getUdis).flatMap(Collection::stream) .collect(Collectors.toList()); distributeTargetPower(udiEventsPerUdi, ptuDate, ptuDuration, deviceMessageDtoList, ptuIndex, targetPower, udis); }));/*from w ww . ja v a2 s .c o m*/ return deviceMessageDtoList; }
From source file:energy.usef.dso.workflow.validate.gridsafetyanalysis.DsoGridSafetyAnalysisCoordinator.java
License:Apache License
/** * This method process the StoreGridSafetyAnalysisEvent. Now that gridsafety PBC is async, * this process is completely seperate from the initiation of the GSA. * * @param event/* w w w . jav a2 s .c o m*/ */ @Asynchronous public void saveAndProcessGridSafetyAnalysis(@Observes StoreGridSafetyAnalysisEvent event) throws BusinessValidationException { eventValidationService.validateEventPeriodTodayOrInFuture(event); LocalDate period = event.getPeriod(); String entityAddress = event.getCongestionPointEntityAddress(); List<PtuPrognosis> lastPrognosisList = findLastPrognoses(period, entityAddress); LOGGER.debug("Storing Grid Safety Analysis for {} on {}", entityAddress, period); boolean aggregatorsAvailable = 0 < dsoPlanboardBusinessService .countActiveAggregatorsForCongestionPointOnDay(entityAddress, period); LOGGER.debug("Aggregators available: {} ", aggregatorsAvailable); long sequence = sequenceGeneratorService.next(); // re-group by ptu index Map<Integer, List<PtuPrognosis>> prognosisByPtuIndex = lastPrognosisList.stream() .collect(Collectors.groupingBy(p -> p.getPtuContainer().getPtuIndex())); List<PtuGridSafetyAnalysisDto> flexRequestList = new ArrayList<>(); ConnectionGroup connectionGroup = corePlanboardBusinessService.findConnectionGroup(entityAddress); Map<Integer, PtuContainer> ptuContainers = dsoPlanboardBusinessService.findPTUContainersForPeriod(period); int numberOfRowsDeleted = dsoPlanboardBusinessService.deletePreviousGridSafetyAnalysis(entityAddress, period); LOGGER.debug("Number of previous GSA records deleted {}", numberOfRowsDeleted); int currentPtuIndex = PtuUtil.getPtuIndex(DateTimeUtil.getCurrentDateTime(), config.getIntegerProperty(ConfigParam.PTU_DURATION)); LocalDate today = DateTimeUtil.getCurrentDate(); boolean futurePeriod = period.isAfter(today); int startPtu; if (futurePeriod) { startPtu = 1; } else { startPtu = currentPtuIndex; } GridSafetyAnalysisDto gridSafetyAnalysisDto = event.getGridSafetyAnalysisDto(); for (int ptuIndex = startPtu; ptuIndex <= gridSafetyAnalysisDto.getPtus().size(); ptuIndex++) { PtuGridSafetyAnalysisDto ptuGridSafetyAnalysisDto = gridSafetyAnalysisDto.getPtus().get(ptuIndex - 1); GridSafetyAnalysis gridSafetyAnalysis; gridSafetyAnalysis = createGridSafetyAnalysis(sequence, prognosisByPtuIndex, connectionGroup, ptuContainers, ptuGridSafetyAnalysisDto); dsoPlanboardBusinessService.storeGridSafetyAnalysis(gridSafetyAnalysis); PtuState ptuState = corePlanboardBusinessService.findOrCreatePtuState( gridSafetyAnalysis.getPtuContainer(), gridSafetyAnalysis.getConnectionGroup()); // Changing PTU regime and preparing gridSafetyAnalysis items for further processing if (DispositionTypeDto.REQUESTED.equals(ptuGridSafetyAnalysisDto.getDisposition()) && aggregatorsAvailable) { ptuState.setRegime(RegimeType.YELLOW); flexRequestList.add(ptuGridSafetyAnalysisDto); } } // fire next steps if (flexRequestList.isEmpty()) { // no flex requests possible, start the coloring process startColoringProcess(event); } else { // there are flex requests possible, send them sendFlexRequests(event, flexRequestList); } LOGGER.debug("Ended saving GridSafetyAnalysis"); }
From source file:es.usc.citius.servando.calendula.util.PickupUtils.java
License:Open Source License
public Pair<LocalDate, List<PickupInfo>> getBestDay() { if (this.bestDay != null) { return this.bestDay; }/*from w w w .j a v a 2s .c o m*/ HashMap<LocalDate, List<PickupInfo>> bestDays = new HashMap<>(); if (pickups.size() > 0) { LocalDate today = LocalDate.now(); LocalDate first = LocalDate.now(); LocalDate now = LocalDate.now().minusDays(MAX_DAYS); if (now.getDayOfWeek() == DateTimeConstants.SUNDAY) { now = now.plusDays(1); } // get the date of the first med we can take from 10 days ago for (PickupInfo p : pickups) { if (p.from().isAfter(now) && !p.taken()) { first = p.from(); break; } } for (int i = 0; i < 10; i++) { LocalDate d = first.plusDays(i); if (!d.isAfter(today) && d.getDayOfWeek() != DateTimeConstants.SUNDAY) { // only take care of days after today that are not sundays continue; } // compute the number of meds we cant take for each day for (PickupInfo p : pickups) { // get the pickup take secure interval DateTime iStart = p.from().toDateTimeAtStartOfDay(); DateTime iEnd = p.from().plusDays(MAX_DAYS - 1).toDateTimeAtStartOfDay(); Interval interval = new Interval(iStart, iEnd); // add the pickup to the daily list if we can take it if (!p.taken() && interval.contains(d.toDateTimeAtStartOfDay())) { if (!bestDays.containsKey(d)) { bestDays.put(d, new ArrayList<PickupInfo>()); } bestDays.get(d).add(p); } } } // select the day with the highest number of meds int bestDayCount = 0; LocalDate bestOption = null; Set<LocalDate> localDates = bestDays.keySet(); ArrayList<LocalDate> sorted = new ArrayList<>(localDates); Collections.sort(sorted); for (LocalDate day : sorted) { List<PickupInfo> pks = bestDays.get(day); Log.d("PickupUtils", day.toString("dd/MM/YYYY") + ": " + pks.size()); if (pks.size() >= bestDayCount) { bestDayCount = pks.size(); bestOption = day; if (bestOption.getDayOfWeek() == DateTimeConstants.SUNDAY) { bestOption = bestOption.minusDays(1); } } } if (bestOption != null) { this.bestDay = new Pair<>(bestOption, bestDays.get(bestOption)); return this.bestDay; } } return null; }
From source file:fm.last.commons.lang.time.DateRange.java
License:Apache License
private void validateDates(LocalDate firstDate, LocalDate lastDate) { if (firstDate == null) { throw new IllegalArgumentException("First date cannot be null"); }/*ww w . jav a 2 s .c o m*/ if (lastDate == null) { throw new IllegalArgumentException("Last date cannot be null"); } if (firstDate.isAfter(lastDate)) { throw new IllegalArgumentException("First date cannot be after last date"); } }
From source file:fr.mycellar.application.booking.impl.BookingEventServiceImpl.java
License:Open Source License
@Override public BookingEvent nextBookingEvent(Integer id) throws BusinessException { BookingEvent bookingEvent = getById(id); if (bookingEvent == null) { throw new BusinessException(BusinessError.OTHER_00003); }//from ww w. j a v a 2 s .c o m BookingEvent next = new BookingEvent(); next.setName(bookingEvent.getName()); LocalDate today = new LocalDate(); LocalDate friday = today.withDayOfWeek(DateTimeConstants.FRIDAY); if (!friday.isAfter(today)) { friday = friday.plusWeeks(1); } next.setStart(friday); next.setEnd(friday.plusWeeks(1).withDayOfWeek(DateTimeConstants.WEDNESDAY)); for (BookingBottle bookingBottle : bookingEvent.getBottles()) { BookingBottle copy = new BookingBottle(); copy.setBookingEvent(next); copy.setBottle(new Bottle()); copy.getBottle().setFormat(bookingBottle.getBottle().getFormat()); Wine wine; Wine original = bookingBottle.getBottle().getWine(); if (original.getVintage() == null) { wine = original; } else { wine = wineService.find(original.getProducer(), original.getAppellation(), original.getType(), original.getColor(), original.getName(), original.getVintage() + 1); if (wine == null) { wine = wineService .createVintages(original, original.getVintage() + 1, original.getVintage() + 1).get(0); } } copy.getBottle().setWine(wine); copy.setMax(bookingBottle.getMax()); copy.setPosition(bookingBottle.getPosition()); copy.setPrice(bookingBottle.getPrice()); copy.setUrl(bookingBottle.getUrl()); next.getBottles().add(copy); } return save(next); }