List of usage examples for org.joda.time LocalDateTime LocalDateTime
public LocalDateTime()
From source file:com.the.todo.MainToDoController.java
License:MIT License
private void generateAllReminders() { LocalDateTime currentDateTime = new LocalDateTime(); LocalDateTime tomorrowDateTime = new LocalDateTime().plusDays(1); for (ToDo todo : appLogic.getTodoStorage().getAll()) { if (todo.isDeadlineToDo()) { if (todo.getEndDate().isBefore(tomorrowDateTime) && todo.getEndDate().isAfter(currentDateTime)) { new ReminderTask(todo, currentDateTime); }/*w ww. j a va 2 s.c om*/ } } }
From source file:com.the.todo.parser.NattyParserWrapper.java
License:MIT License
public List<DateGroup> parseDateOnly(String date) { CalendarSource.setBaseDate(new LocalDateTime().withTime(23, 59, 00, 00).toDate()); return nattyParser.parse(date); }
From source file:com.weekcalendar.utils.CalUtil.java
License:Open Source License
/** * Initial calculation of the week// w w w .j a v a 2s .co m */ public void calculate(Context mContext) { //Initializing JodaTime JodaTimeAndroid.init(mContext); //Initializing Start with current month final LocalDateTime currentDateTime = new LocalDateTime(); setStartDate(currentDateTime.getYear(), currentDateTime.getMonthOfYear(), currentDateTime.getDayOfMonth()); int weekGap = CalUtil.mDateGap(currentDateTime.dayOfWeek().getAsText().substring(0, 3).toLowerCase()); if (weekGap != 0) { //if the current date is not the first day of the week the rest of days is added //Calendar set to the current date Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, -weekGap); //now the date is weekGap days back LocalDateTime ldt = LocalDateTime.fromCalendarFields(calendar); setStartDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth()); } }
From source file:de.appsolve.padelcampus.admin.controller.bookings.AdminBookingsReservationsController.java
@Override public ModelAndView postEditView(@ModelAttribute("Model") ReservationRequest reservationRequest, HttpServletRequest request, BindingResult bindingResult) { ModelAndView addView = getAddView(reservationRequest); validator.validate(reservationRequest, bindingResult); if (bindingResult.hasErrors()) { return addView; }/* www .j a v a 2 s . com*/ try { Player player = sessionUtil.getUser(request); //calculate reservation bookings, taking into account holidays LocalDate date = reservationRequest.getStartDate(); LocalDate endDate = reservationRequest.getEndDate(); List<Booking> bookings = new ArrayList<>(); List<Booking> failedBookings = new ArrayList<>(); LocalDateTime blockingTime = new LocalDateTime(); while (date.compareTo(endDate) <= 0) { Set<CalendarWeekDay> calendarWeekDays = reservationRequest.getCalendarWeekDays(); for (CalendarWeekDay calendarWeekDay : calendarWeekDays) { if (calendarWeekDay.ordinal() + 1 == date.getDayOfWeek()) { try { List<CalendarConfig> calendarConfigs = calendarConfigDAO.findFor(date); //throws CalendarConfigException Iterator<CalendarConfig> iterator = calendarConfigs.iterator(); while (iterator.hasNext()) { CalendarConfig calendarConfig = iterator.next(); if (!bookingUtil.isHoliday(date, calendarConfig)) { for (Offer offer : reservationRequest.getOffers()) { Booking booking = new Booking(); booking.setAmount(BigDecimal.ZERO); booking.setBlockingTime(blockingTime); booking.setBookingDate(date); booking.setBookingTime(reservationRequest.getStartTime()); booking.setBookingType(BookingType.reservation); booking.setComment(reservationRequest.getComment()); booking.setConfirmed(Boolean.TRUE); booking.setCurrency(Currency.EUR); booking.setDuration(getDuration(reservationRequest, calendarConfig)); booking.setPaymentConfirmed(reservationRequest.getPaymentConfirmed()); booking.setPaymentMethod(PaymentMethod.Reservation); booking.setPlayer(player); booking.setUUID(BookingUtil.generateUUID()); booking.setOffer(offer); booking.setPublicBooking(reservationRequest.getPublicBooking()); //we call this inside the loop to prevent overbooking List<Booking> confirmedBookings = bookingDAO .findBlockedBookingsForDate(date); OfferDurationPrice offerDurationPrice = bookingUtil.getOfferDurationPrice( calendarConfigs, confirmedBookings, booking.getBookingDate(), booking.getBookingTime(), offer); if (offerDurationPrice == null) { failedBookings.add(booking); continue; } else { BigDecimal price = offerDurationPrice.getDurationPriceMap() .get(booking.getDuration().intValue()); booking.setAmount(price); } TimeSlot timeSlot = new TimeSlot(); timeSlot.setDate(date); timeSlot.setStartTime(reservationRequest.getStartTime()); timeSlot.setEndTime(reservationRequest.getEndTime()); timeSlot.setConfig(calendarConfig); Long bookingSlotsLeft = bookingUtil.getBookingSlotsLeft(timeSlot, offer, confirmedBookings); if (bookingSlotsLeft < 1) { failedBookings.add(booking); continue; } //we save the booking directly to prevent overbookings booking = bookingDAO.saveOrUpdate(booking); bookings.add(booking); } } break; } break; } catch (CalendarConfigException e) { LOG.warn( "Caught calendar config exception during add reservation request. This may be normal (for holidays)", e); Booking failedBooking = new Booking(); failedBooking.setPlayer(player); failedBooking.setBookingDate(date); failedBooking.setBookingTime(reservationRequest.getStartTime()); failedBookings.add(failedBooking); } } } date = date.plusDays(1); } if (!failedBookings.isEmpty()) { throw new Exception(msg.get("UnableToReserveAllDesiredTimes", new Object[] { StringUtils.join(bookings, "<br/>"), StringUtils.join(failedBookings, "<br/>") })); } if (bookings.isEmpty()) { throw new Exception(msg.get("NoCourtReservationsForSelectedDateTime")); } return new ModelAndView("redirect:/admin/bookings/reservations"); } catch (Exception e) { LOG.error(e, e); bindingResult.addError(new ObjectError("comment", e.getMessage())); return addView; } }
From source file:de.appsolve.padelcampus.admin.controller.bookings.AdminBookingsReservationsController.java
@RequestMapping(method = POST, value = "booking/{bookingId}") public ModelAndView postEditBooking(@PathVariable("bookingId") Long bookingId, @Valid @ModelAttribute("Model") ReservationRequest model, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return getEditView(model); }//from w ww . j ava 2 s .c o m try { LocalDate today = new LocalDate(); LocalTime now = new LocalTime(); if (model.getStartDate().compareTo(today) < 0 || (model.getStartDate().equals(today) && model.getStartTime().compareTo(now) < 0)) { throw new Exception(msg.get("RequestedTimeIsInThePast")); } /* only one offer possible */ Offer offer = model.getOffers().iterator().next(); /* make sure to not modify booking before we know it can be changed b/c auf auto transaction commit */ Booking booking = bookingDAO.findById(bookingId); List<CalendarConfig> calendarConfigs = calendarConfigDAO.findFor(model.getStartDate()); //throws CalendarConfigException Iterator<CalendarConfig> iterator = calendarConfigs.iterator(); while (iterator.hasNext()) { CalendarConfig calendarConfig = iterator.next(); if (!bookingUtil.isHoliday(model.getStartDate(), calendarConfig)) { List<Booking> confirmedBookings = bookingDAO.findBlockedBookingsForDate(model.getStartDate()); //remove the current booking as we want to update it confirmedBookings.remove(booking); OfferDurationPrice offerDurationPrice = bookingUtil.getOfferDurationPrice(calendarConfigs, confirmedBookings, model.getStartDate(), model.getStartTime(), offer); if (offerDurationPrice != null) { TimeSlot timeSlot = new TimeSlot(); timeSlot.setDate(model.getStartDate()); timeSlot.setStartTime(model.getStartTime()); timeSlot.setEndTime(model.getEndTime()); timeSlot.setConfig(calendarConfig); Long bookingSlotsLeft = bookingUtil.getBookingSlotsLeft(timeSlot, offer, confirmedBookings); if (bookingSlotsLeft >= 1) { BigDecimal price = offerDurationPrice.getDurationPriceMap() .get(booking.getDuration().intValue()); booking.setAmount(price); booking.setBlockingTime(new LocalDateTime()); booking.setBookingDate(model.getStartDate()); booking.setBookingTime(model.getStartTime()); booking.setComment(model.getComment()); booking.setDuration(getDuration(model, calendarConfig)); booking.setOffer(offer); booking.setOfferOptions(model.getOfferOptions()); booking.setPaymentConfirmed(model.getPaymentConfirmed()); booking.setPaymentMethod(PaymentMethod.Reservation); booking.setPublicBooking(model.getPublicBooking()); bookingDAO.saveOrUpdate(booking); return redirectToIndex(); } } } } throw new Exception(msg.get("NoCourtReservationsForSelectedDateTime")); } catch (Exception e) { LOG.error(e); bindingResult.addError(new ObjectError("id", e.getMessage())); return getEditView(model); } }
From source file:de.appsolve.padelcampus.controller.bookings.BookingsController.java
@RequestMapping(value = "{day}/{time}/confirm", method = POST) public ModelAndView confirmBooking(HttpServletRequest request, @PathVariable("day") String day, @PathVariable("time") String time, @RequestParam(value = "public-booking", defaultValue = "false") Boolean isPublicBooking, @RequestParam(value = "accept-cancellation-policy", defaultValue = "false") Boolean isCancellationPolicyAccepted, RedirectAttributes redirectAttributes) throws Exception { Booking booking = sessionUtil.getBooking(request); ModelAndView confirmView = getBookingConfirmView(booking); try {/* w w w .ja va 2 s . co m*/ if (booking == null) { throw new Exception(msg.get("SessionTimeout")); } if (booking.getConfirmed()) { throw new Exception(msg.get("BookingAlreadyConfirmed")); } if (!isCancellationPolicyAccepted) { throw new Exception(msg.get("BookingCancellationPolicyNotAccepted")); } try { //rerun checks (date time valid, overbooked...) validateAndAddObjectsToView(null, request, booking, day, time, booking.getOffer()); validatePaymentMethod(booking.getPlayer(), booking); } catch (Exception e) { //return to bookings page where user can modify booking ModelAndView redirectView = new ModelAndView( String.format("redirect:/bookings/%s/%s/offer/%s", day, time, booking.getOffer().getId())); redirectAttributes.addFlashAttribute("error", e.getMessage()); return redirectView; } booking.setPublicBooking(isPublicBooking); booking.setBlockingTime(new LocalDateTime()); booking.setUUID(BookingUtil.generateUUID()); bookingDAO.saveOrUpdate(booking); switch (booking.getPaymentMethod()) { case Subscription: case Cash: case ExternalVoucher: if (booking.getConfirmed()) { throw new Exception(msg.get("BookingAlreadyConfirmed")); } return getRedirectToSuccessView(booking); case PayPal: return bookingsPayPalController.redirectToPaypal(booking, request); case PayDirekt: return bookingsPayDirektController.redirectToPayDirekt(booking, request); case DirectDebit: return bookingsPayMillController.redirectToDirectDebit(booking); case CreditCard: return bookingsPayMillController.redirectToCreditCard(booking); case Voucher: return bookingsVoucherController.redirectToVoucher(booking); default: confirmView.addObject("error", booking.getPaymentMethod() + " not implemented"); return confirmView; } } catch (Exception e) { LOG.error("Error while processing booking request: " + e.getMessage()); confirmView.addObject("error", e.getMessage()); return confirmView; } }
From source file:de.appsolve.padelcampus.controller.events.EventsBookingController.java
@RequestMapping(value = "{eventId}/confirm", method = POST) public ModelAndView confirmBooking(HttpServletRequest request) throws Exception { Booking booking = sessionUtil.getBooking(request); ModelAndView confirmView = getBookingConfirmView(booking); try {//from w w w. java 2 s. co m if (booking == null) { throw new Exception(msg.get("SessionTimeout")); } String publicBooking = request.getParameter("public-booking"); Boolean isPublicBooking = !StringUtils.isEmpty(publicBooking) && publicBooking.equalsIgnoreCase("on"); booking.setPublicBooking(isPublicBooking); String cancellationPolicyCheckbox = request.getParameter("accept-cancellation-policy"); if (StringUtils.isEmpty(cancellationPolicyCheckbox) || !cancellationPolicyCheckbox.equals("on")) { throw new Exception(msg.get("BookingCancellationPolicyNotAccepted")); } if (booking.getConfirmed()) { throw new Exception(msg.get("BookingAlreadyConfirmed")); } isEventBookingPossible(booking); booking.setBlockingTime(new LocalDateTime()); booking.setUUID(BookingUtil.generateUUID()); if (booking.getCommunity() != null) { SortedSet<Player> communityPlayers = new TreeSet<>(); if (booking.getPlayerParticipates()) { communityPlayers.add(booking.getPlayer()); } communityPlayers.addAll(booking.getPlayers()); booking.getCommunity().setPlayers(communityPlayers); booking.setCommunity(communityDAO.saveOrUpdate(booking.getCommunity())); } bookingDAO.saveOrUpdate(booking); switch (booking.getPaymentMethod()) { case Cash: case ExternalVoucher: if (booking.getConfirmed()) { throw new Exception(msg.get("BookingAlreadyConfirmed")); } return new ModelAndView("redirect:/events/bookings/" + booking.getUUID() + "/success"); case PayPal: return bookingsPayPalController.redirectToPaypal(booking, request); case PayDirekt: return bookingsPayDirektController.redirectToPayDirekt(booking, request); case DirectDebit: return bookingsPayMillController.redirectToDirectDebit(booking); case CreditCard: return bookingsPayMillController.redirectToCreditCard(booking); case Voucher: return bookingsVoucherController.redirectToVoucher(booking); default: confirmView.addObject("error", booking.getPaymentMethod() + " not implemented"); return confirmView; } } catch (Exception e) { LOG.warn("Error while processing booking request: " + e.getMessage(), e); confirmView.addObject("error", e.getMessage()); return confirmView; } }
From source file:de.appsolve.padelcampus.db.model.BaseEntity.java
@PreUpdate public void updateLastUpdated() { setLastUpdated(new LocalDateTime()); }
From source file:de.appsolve.padelcampus.listener.SessionEventListener.java
@Override public void sessionDestroyed(HttpSessionEvent se) { if (activeSessions > 0) { activeSessions--;/*from ww w . jav a 2s . c o m*/ } initDependencies(se.getSession().getServletContext()); LocalDateTime now = new LocalDateTime(); Booking booking = sessionUtil.getBooking(se.getSession()); if (booking != null) { if (booking.getId() != null) { //get latest booking from DB booking = bookingBaseDAO.findById(booking.getId()); } cancelBooking(booking, now); } //also look for other blocking bookings that might no have been deleted LocalDateTime maxAge = now.minusSeconds(se.getSession().getMaxInactiveInterval()); List<Booking> findBlockedBookings = bookingBaseDAO.findUnpaidBlockingBookings(); for (Booking blockingBooking : findBlockedBookings) { cancelBooking(blockingBooking, maxAge); } }
From source file:de.avanux.smartapplianceenabler.appliance.Appliance.java
License:Open Source License
@Override public void startingCurrentDetected() { logger.debug("Activating next sufficient timeframe interval after starting current has been detected"); LocalDateTime now = new LocalDateTime(); TimeframeInterval timeframeInterval; Schedule forcedSchedule = getForcedSchedule(now); if (forcedSchedule != null) { logger.debug("Forcing schedule " + forcedSchedule); timeframeInterval = Schedule.getCurrentOrNextTimeframeInterval(now, Collections.singletonList(forcedSchedule), false, true); } else {/*from w ww .ja v a 2s .c om*/ timeframeInterval = Schedule.getCurrentOrNextTimeframeInterval(now, schedules, false, true); } runningTimeMonitor.activateTimeframeInterval(now, timeframeInterval); }