Example usage for org.joda.time LocalDate isBefore

List of usage examples for org.joda.time LocalDate isBefore

Introduction

In this page you can find the example usage for org.joda.time LocalDate isBefore.

Prototype

public boolean isBefore(ReadablePartial partial) 

Source Link

Document

Is this partial earlier than the specified partial.

Usage

From source file:controllers.sale.Campaigns.java

License:Open Source License

/**
 * Kayit isleminden once form uzerinde bulunan verilerin uygunlugunu kontrol eder
 * /*from   w ww  . java 2  s. co  m*/
 * @param filledForm
 */
private static void checkConstraints(Form<SaleCampaign> filledForm) {
    SaleCampaign model = filledForm.get();

    if (SaleCampaign.isUsedForElse("name", model.name, model.id)) {
        filledForm.reject("name", Messages.get("not.unique", model.name));
    }

    if (model.id == null) {
        LocalDate today = new DateTime().toLocalDate();
        LocalDate startDate = new DateTime(model.startDate).toLocalDate();
        LocalDate endDate = new DateTime(model.endDate).toLocalDate();

        if (endDate.isBefore(startDate)) {
            filledForm.reject("startDate", Messages.get("error.dateRange"));
        } else if (startDate.isBefore(today)) {
            filledForm.reject("startDate", Messages.get("error.dateRange.x", Messages.get("date.start")));
        }
    }
}

From source file:courtscheduler.domain.DateConstraint.java

License:Apache License

public Integer[] findDayOfWeek(int weekday) {
    LocalDate firstDay = info.getConferenceStartDate().withDayOfWeek(weekday);
    ArrayList<Integer> days = new ArrayList<Integer>();
    if (firstDay.isBefore(info.getConferenceStartDate())) {
        firstDay.plusWeeks(1);//from  w w w  .  j  ava  2s  .  c o m
    }
    while (firstDay.isBefore(info.getConferenceEndDate()) || firstDay.equals(info.getConferenceEndDate())) {
        Integer index = Days.daysBetween(info.getConferenceStartDate(), firstDay).getDays();
        if (index >= 0) {
            days.add(index);
        }
        firstDay = firstDay.plusWeeks(1);
    }
    return days.toArray(new Integer[days.size()]);
}

From source file:courtscheduler.persistence.CourtScheduleInfo.java

License:Apache License

public int configure() {
    raw_lines = slurpConfigFile(this.filepath);
    if (raw_lines.size() == 0) {
        error(true,/*from   w w w  . j  ava2  s .co m*/
                "Could not read anything from the configuration file." + EOL
                        + "Expected the configuration file to be found at: "
                        + FileSystems.getDefault().getPath(filepath).toAbsolutePath());
    }
    String[] scheduleDescription = new String[0];
    for (String line : raw_lines) {
        if (line.startsWith(";", 0) || line.trim().length() == 0) {
            // this line is a comment or empty line
            continue;
        }
        String[] lineComponents = line.split("=");
        if (lineComponents.length < 2) {
            System.out.println("could not interpret line: " + line);
            continue;
        }

        String key = lineComponents[0].trim();
        String value = lineComponents[1].trim();

        if (key.equals("conference_start")) {
            this.conferenceStartDate = parseDateString(value);
        } else if (key.equals("conference_end")) {
            this.conferenceEndDate = parseDateString(value);
        } else if (key.equals("court_count")) {
            this.numberOfCourts = Integer.parseInt(value);
        } else if (key.equals("timeslots_count")) {
            this.numberOfTimeSlotsPerDay = Integer.parseInt(value);
        } else if (key.equals("timeslot_duration_minutes")) {
            this.timeslotDurationInMinutes = Integer.parseInt(value);
        } else if (key.equals("timeslots_start")) {
            this.timeslotMidnightOffsetInMinutes = timeStringToMinutes(value);
        } else if (key.startsWith("conference")) {
            this.parseConferenceDays(value);
        } else if (key.startsWith("holiday")) {
            if (!value.contains("-")) {
                // one date
                holidays.add(LocalDate.parse(value, DateConstraint.dateFormat));
            } else {
                // date range
                LocalDate start = LocalDate.parse(value.substring(0, value.indexOf("-")),
                        DateConstraint.dateFormat);
                LocalDate end = LocalDate.parse(value.substring(value.indexOf("-") + 1),
                        DateConstraint.dateFormat);
                LocalDate next = start;
                while (next.isBefore(end)) {
                    holidays.add(next);
                    next = next.plusDays(1);
                }
                holidays.add(end);
            }
        } else if (key.startsWith("schedule_description")) {
            scheduleDescription = value.split(", ");
        }

        else if (key.startsWith("input_file")) {
            inputFileLocation = value;
        }

        else if (key.startsWith("output_folder")) {
            outputFolderLocation = value;
        }
    }
    DateConstraint.setStandardDates(this.createStandardSchedule(scheduleDescription));
    return 0;
}

From source file:cz.krtinec.birthday.dto.Zodiac.java

License:Open Source License

public static Zodiac toZodiac(LocalDate birthday) {
    for (Zodiac zodiac : values()) {
        LocalDate fromWithYear = zodiac.from.withYear(birthday.getYear());
        LocalDate toWithYear = zodiac.to.withYear(birthday.getYear());

        if (birthday.getMonthOfYear() == 12 && Zodiac.CAPRICORN.equals(zodiac)) {
            toWithYear = toWithYear.plusYears(1);
        } else if (birthday.getMonthOfYear() == 1 && Zodiac.CAPRICORN.equals(zodiac)) {
            fromWithYear = fromWithYear.minusYears(1);
        }/*from   ww  w. j  a  va 2 s.  c om*/

        if ((fromWithYear.isBefore(birthday) || fromWithYear.isEqual(birthday))
                && (toWithYear.isAfter(birthday) || toWithYear.isEqual(birthday))) {
            return zodiac;
        }
    }

    throw new IllegalArgumentException("Cannot find zodiac sign for date: " + birthday);
}

From source file:de.appsolve.padelcampus.admin.controller.bookings.AdminBookingsReservationsController.java

@Override
public ModelAndView showIndex(HttpServletRequest request, Pageable pageable, String search) {
    String startDateStr = request.getParameter("startDate");
    String endDateStr = request.getParameter("endDate");
    LocalDate startDate = sessionUtil.getBookingListStartDate(request);
    if (startDate == null) {
        startDate = new LocalDate();
    }//from  w  w  w .j a va2  s  .  com
    if (!StringUtils.isEmpty(startDateStr)) {
        try {
            startDate = LocalDate.parse(startDateStr, DATE_HUMAN_READABLE);
        } catch (IllegalArgumentException e) {
            //ignore
        }
    }
    sessionUtil.setBookingListStartDate(request, startDate);
    LocalDate endDate = new LocalDate(startDate);
    if (!StringUtils.isEmpty(endDateStr)) {
        try {
            endDate = LocalDate.parse(endDateStr, DATE_HUMAN_READABLE);
        } catch (IllegalArgumentException e) {
            //ignore
        }
    }
    if (endDate.isBefore(startDate)) {
        endDate = new LocalDate(startDate);
    }

    DateRange dateRange = new DateRange();
    dateRange.setStartDate(startDate);
    dateRange.setEndDate(endDate);
    return getIndexView(dateRange);
}

From source file:de.appsolve.padelcampus.utils.BookingUtil.java

public void addWeekView(HttpServletRequest request, LocalDate selectedDate, List<Facility> selectedFacilities,
        ModelAndView mav, Boolean onlyFutureTimeSlots, Boolean preventOverlapping)
        throws JsonProcessingException {
    //calculate date configuration for datepicker
    LocalDate today = new LocalDate(DEFAULT_TIMEZONE);
    LocalDate firstDay = today.dayOfMonth().withMinimumValue();
    LocalDate lastDay = getLastBookableDay(request).plusDays(1);
    List<CalendarConfig> calendarConfigs = calendarConfigDAO.findBetween(firstDay, lastDay);
    Collections.sort(calendarConfigs);
    Map<String, DatePickerDayConfig> dayConfigs = getDayConfigMap(firstDay, lastDay, calendarConfigs);

    List<Booking> confirmedBookings = bookingDAO.findBlockedBookingsBetween(firstDay, lastDay);

    //calculate available time slots
    List<TimeSlot> timeSlots = new ArrayList<>();
    List<LocalDate> weekDays = new ArrayList<>();
    for (int i = 1; i <= CalendarWeekDay.values().length; i++) {
        LocalDate date = selectedDate.withDayOfWeek(i);
        weekDays.add(date);/*from   w ww.j  a  v a 2s.  co  m*/
        if ((!onlyFutureTimeSlots || !date.isBefore(today)) && lastDay.isAfter(date)) {
            try {
                //generate list of bookable time slots
                timeSlots.addAll(getTimeSlotsForDate(date, calendarConfigs, confirmedBookings,
                        onlyFutureTimeSlots, preventOverlapping));
            } catch (CalendarConfigException e) {
                //safe to ignore
            }
        }
    }

    SortedSet<Offer> offers = new TreeSet<>();
    List<TimeRange> rangeList = new ArrayList<>();
    //Map<TimeRange, List<TimeSlot>> rangeList = new TreeMap<>();
    for (TimeSlot slot : timeSlots) {
        Set<Offer> slotOffers = slot.getConfig().getOffers();
        offers.addAll(slotOffers);

        TimeRange range = new TimeRange();
        range.setStartTime(slot.getStartTime());
        range.setEndTime(slot.getEndTime());

        if (rangeList.contains(range)) {
            range = rangeList.get(rangeList.indexOf(range));
        } else {
            rangeList.add(range);
        }

        List<TimeSlot> slotis = range.getTimeSlots();
        slotis.add(slot);
        range.setTimeSlots(slotis);
    }
    Collections.sort(rangeList);

    List<Offer> selectedOffers = new ArrayList<>();
    if (selectedFacilities.isEmpty()) {
        selectedOffers = offerDAO.findAll();
    } else {
        for (Facility facility : selectedFacilities) {
            selectedOffers.addAll(facility.getOffers());
        }
    }
    Collections.sort(selectedOffers);

    mav.addObject("dayConfigs", objectMapper.writeValueAsString(dayConfigs));
    mav.addObject("maxDate", lastDay.toString());
    mav.addObject("Day", selectedDate);
    mav.addObject("NextMonday", selectedDate.plusDays(8 - selectedDate.getDayOfWeek()));
    mav.addObject("PrevSunday", selectedDate.minusDays(selectedDate.getDayOfWeek()));
    mav.addObject("WeekDays", weekDays);
    mav.addObject("RangeMap", rangeList);
    mav.addObject("Offers", offers);
    mav.addObject("SelectedOffers", selectedOffers);
    mav.addObject("SelectedFacilities", selectedFacilities);
    mav.addObject("Facilities", facilityDAO.findAll());
}

From source file:de.iteratec.iteraplan.model.attribute.Timeseries.java

License:Open Source License

public TimeseriesEntry getLatestEntry() {
    if (values.isEmpty()) {
        return null;
    }//  w w w.  ja  v  a2 s  . c  o m

    LocalDate latestDate = new LocalDate(0);
    for (LocalDate date : values.keySet()) {
        if (latestDate.isBefore(date)) {
            latestDate = date;
        }
    }
    return new TimeseriesEntry(latestDate.toDate(), values.get(latestDate));
}

From source file:de.iteratec.iteraplan.model.attribute.Timeseries.java

License:Open Source License

public void validate() {
    LocalDate now = LocalDate.now();
    for (LocalDate entryDate : values.keySet()) {
        if (now.isBefore(entryDate)) {
            throw new IteraplanBusinessException(IteraplanErrorMessages.TIMESERIES_INVALID_FUTURE_DATE);
        }//from   w w w.  ja  va 2  s .  c  om
    }
}

From source file:de.sub.goobi.forms.CalendarForm.java

License:Open Source License

/**
 * The method setLastAppearance() will be called by Faces to store a new
 * value of the read-write property "lastAppearance", which represents the
 * date of last appearance of the block currently showing. The event will be
 * used to either alter the date of last appearance of the block defined by
 * the blockShowing? field or, in case that a new block is under edit, to
 * initially set its the date of last appearance.
 *
 * @param lastAppearance/*from w w w .j  av a2s . c  o m*/
 *            new date of last appearance
 */
public void setLastAppearance(String lastAppearance) {
    LocalDate newLastAppearance;
    try {
        newLastAppearance = parseDate(lastAppearance, "lastAppearance");
    } catch (IllegalArgumentException e) {
        newLastAppearance = blockShowing != null ? blockShowing.getLastAppearance() : null;
    }
    try {
        if (blockShowing != null) {
            if (blockChangerUnchanged) {
                if (firstAppearanceIsToChange == null) {
                    if (blockShowing.getLastAppearance() == null
                            || !blockShowing.getLastAppearance().isEqual(newLastAppearance)) {
                        if (blockShowing.getFirstAppearance() != null
                                && newLastAppearance.isBefore(blockShowing.getFirstAppearance())) {
                            Helper.setFehlerMeldung("calendar.block.negative");
                            return;
                        }
                        blockShowing.setLastAppearance(newLastAppearance);
                        checkBlockPlausibility();
                        navigate();
                    }
                } else {
                    if (blockShowing.getLastAppearance() == null
                            || !blockShowing.getLastAppearance().isEqual(newLastAppearance)) {
                        if (newLastAppearance.isBefore(firstAppearanceIsToChange)) {
                            Helper.setFehlerMeldung("calendar.block.negative");
                            return;
                        }
                        blockShowing.setPublicationPeriod(firstAppearanceIsToChange, newLastAppearance);
                    } else {
                        if (blockShowing.getLastAppearance() != null
                                && blockShowing.getLastAppearance().isBefore(firstAppearanceIsToChange)) {
                            Helper.setFehlerMeldung("calendar.block.negative");
                            return;
                        }
                        blockShowing.setFirstAppearance(firstAppearanceIsToChange);
                    }
                    checkBlockPlausibility();
                    navigate();
                }
            }
        } else {
            if (newLastAppearance != null) {
                blockShowing = new Block(course);
                blockShowing.setLastAppearance(newLastAppearance);
                course.add(blockShowing);
            }
        }
    } catch (IllegalArgumentException e) {
        Helper.setFehlerMeldung("calendar.block.lastAppearance.rejected");
    } finally {
        firstAppearanceIsToChange = null;
    }
}

From source file:domainapp.dom.reserva.Reservas.java

License:Apache License

@Programmatic
public String validate1CrearReserva(final LocalDate fechaIn) {

    LocalDate hoyy = LocalDate.now();
    if (fechaIn.isBefore(hoyy)) {
        return "Una Reserva no puede empezar en el pasado";
    }/*from  w  w  w.  j a  va2s  .  c  o m*/

    return null;
}