List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate(Object instant)
From source file:de.appsolve.padelcampus.spring.LocalDateEditor.java
/** * Format the YearMonthDay as String, using the specified format. * * @return DateTime formatted string/*from www . ja v a 2s. c o m*/ */ @Override public String getAsText() { return getValue() != null ? new LocalDate(getValue()).toString(formatter) : ""; }
From source file:de.appsolve.padelcampus.spring.LocalDateEditor.java
/** * Parse the value from the given text, using the specified format. * * @param text// w w w. jav a 2 s.co m * @throws IllegalArgumentException */ @Override public void setAsText(String text) throws IllegalArgumentException { if (allowEmpty && !StringUtils.hasText(text)) { // Treat empty String as null value. setValue(null); } else { setValue(new LocalDate(formatter.parseDateTime(text))); } }
From source file:de.appsolve.padelcampus.utils.BookingUtil.java
public List<TimeSlot> getTimeSlotsForDate(LocalDate selectedDate, List<CalendarConfig> allCalendarConfigs, List<Booking> existingBookings, Boolean onlyFutureTimeSlots, Boolean preventOverlapping) throws CalendarConfigException { List<CalendarConfig> calendarConfigs = calendarConfigUtil.getCalendarConfigsMatchingDate(allCalendarConfigs, selectedDate);//from ww w .ja va2s. c o m Iterator<CalendarConfig> iterator = calendarConfigs.iterator(); while (iterator.hasNext()) { CalendarConfig calendarConfig = iterator.next(); if (isHoliday(selectedDate, calendarConfig)) { iterator.remove(); } } List<TimeSlot> timeSlots = new ArrayList<>(); if (calendarConfigs.size() > 0) { LocalDate today = new LocalDate(DEFAULT_TIMEZONE); //sort all calendar configurations for selected date by start time Collections.sort(calendarConfigs); CalendarConfig previousConfig = null; LocalDateTime time = null; LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE); //generate list of bookable time slots int i = 0; for (CalendarConfig config : calendarConfigs) { i++; LocalDateTime startDateTime = getLocalDateTime(selectedDate, config.getStartTime()); if (time == null) { //on first iteration time = startDateTime; } else if (!time.plusMinutes(previousConfig.getMinInterval()).equals(startDateTime)) { //reset basePriceLastConfig as this is a non contiguous offer previousConfig = null; time = startDateTime; } LocalDateTime endDateTime = getLocalDateTime(selectedDate, config.getEndTime()); while (time.plusMinutes(config.getMinDuration()).compareTo(endDateTime) <= 0) { BigDecimal pricePerMinDuration; if (previousConfig == null) { pricePerMinDuration = config.getBasePrice(); } else { BigDecimal previousConfigBasePricePerMinute = getPricePerMinute(previousConfig); pricePerMinDuration = previousConfigBasePricePerMinute .multiply(new BigDecimal(previousConfig.getMinInterval()), MathContext.DECIMAL128); BigDecimal basePricePerMinute = getPricePerMinute(config); pricePerMinDuration = pricePerMinDuration.add(basePricePerMinute.multiply( new BigDecimal(config.getMinDuration() - previousConfig.getMinInterval()), MathContext.DECIMAL128)); previousConfig = null; } pricePerMinDuration = pricePerMinDuration.setScale(2, RoundingMode.HALF_EVEN); if (onlyFutureTimeSlots) { if (selectedDate.isAfter(today) || time.isAfter(now)) { addTimeSlot(timeSlots, time, config, pricePerMinDuration); } } else { addTimeSlot(timeSlots, time, config, pricePerMinDuration); } time = time.plusMinutes(config.getMinInterval()); } //make sure to display the last min interval of the day if (config.getMinInterval() < config.getMinDuration() && i == calendarConfigs.size()) { if (time.plusMinutes(config.getMinInterval()).compareTo(endDateTime) <= 0) { addTimeSlot(timeSlots, time, config, null); } } previousConfig = config; } //sort time slots by time Collections.sort(timeSlots); //decrease court count for every blocking booking for (TimeSlot timeSlot : timeSlots) { checkForBookedCourts(timeSlot, existingBookings, preventOverlapping); } } return timeSlots; }
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);//w ww. j a v a2 s . c o 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.appsolve.padelcampus.utils.BookingUtil.java
public LocalDate getLastBookableDay(HttpServletRequest request) { Integer maxDate = Constants.CALENDAR_MAX_DATE; if (sessionUtil.getPrivileges(request).contains(Privilege.ManageBookings)) { maxDate = Constants.CALENDAR_MAX_DATE_ADMINS; }// w ww .jav a 2 s. c om return new LocalDate(DEFAULT_TIMEZONE).plusDays(maxDate); }
From source file:de.avanux.smartapplianceenabler.appliance.DayTimeframe.java
License:Open Source License
protected Interval buildMidnightAdjustedInterval(LocalDateTime now) { if (start != null && end != null) { LocalDateTime earliestStartDateTime = new LocalDate(now).toLocalDateTime(start.toLocalTime()); LocalDateTime latestEndDateTime = new LocalDate(now).toLocalDateTime(end.toLocalTime()); if (isOverMidnight(earliestStartDateTime, latestEndDateTime)) { if (now.toLocalTime().isAfter(start.toLocalTime())) { // before midnight latestEndDateTime = latestEndDateTime.plusHours(24); } else if (now.toLocalTime().isBefore(end.toLocalTime())) { // after midnight, before end earliestStartDateTime = earliestStartDateTime.minusHours(24); } else { // after midnight, after end latestEndDateTime = latestEndDateTime.plusHours(24); }//from www . j av a 2s . c o m } return new Interval(earliestStartDateTime.toDateTime(), latestEndDateTime.toDateTime()) .withChronology(ISOChronology.getInstance()); } return null; }