List of usage examples for org.joda.time LocalDate plusDays
public LocalDate plusDays(int days)
From source file:com.stagecents.hxt.domain.Timecard.java
License:Open Source License
public Timecard(Position position, Payroll payroll, LocalDate startDate, LocalDate endDate) { this.position = position; this.payroll = payroll; this.effectiveDateRange = new EffectiveDateInterval(startDate, endDate); // Create daily summary entities for weekly and biweekly timecards Frequency f = payroll.getPayCycle().getFrequency(); if (f.equals(Frequency.W) || f.equals(Frequency.F)) { LocalDate dateWorked = startDate; int calendarDays = f.equals(Frequency.W) ? 7 : 14; for (int i = 0; i < calendarDays; i++) { SummaryHours sh = new SummaryHours(this, i, dateWorked); addSummaryHours(sh);//ww w . j av a 2s. c om dateWorked = dateWorked.plusDays(1); } } }
From source file:com.stagecents.pa.api.ActivityService.java
License:Open Source License
private void updateTimecardHours(Timecard timecard, Position position, LocalDate startDate, LocalDate endDate) { while (timecard.isEffective(startDate)) { Interval duration = new Interval(startDate.toDateTime(activity.getScheduledStart()), startDate.toDateTime(activity.getScheduledEnd())); // Update the time card hours for each element type Iterator<ElementType> iter = position.getElements().iterator(); while (iter.hasNext()) { ElementType e = iter.next(); e.processHours(duration, activity, timecard, position); }// w ww. j av a2 s .c o m // Increment the day startDate = startDate.plusDays(1); if (startDate.isAfter(endDate)) { return; } } }
From source file:com.stagecents.pay.domain.PayCycle.java
License:Open Source License
public LocalDate getCycleEnd(LocalDate cycleStart) { LocalDate result = null;/*from w ww .ja v a 2 s .com*/ if (frequency.equals(Frequency.W)) { result = cycleStart.plusDays(6); } else if (frequency.equals(Frequency.F)) { result = cycleStart.plusDays(13); } else if (frequency.equals(Frequency.SM)) { result = (cycleStart.getDayOfMonth() == 1) ? cycleStart.withDayOfMonth(15) : cycleStart.dayOfMonth().withMaximumValue(); } else if (frequency.equals(Frequency.CM)) { result = cycleStart.dayOfMonth().withMaximumValue(); } else if (frequency.equals(Frequency.Q)) { result = cycleStart.plusMonths(2).dayOfMonth().withMaximumValue(); } return result; }
From source file:com.tysanclan.site.projectewok.beans.impl.DemocracyServiceImpl.java
License:Open Source License
@Override @Transactional(propagation = Propagation.REQUIRED) public void resolveJoinApplication(JoinApplication _application) { JoinApplication application = joinApplicationDAO.load(_application.getId()); if (application != null) { int inFavor = 0, total = 0; for (JoinVerdict verdict : application.getVerdicts()) { if (verdict.isInFavor()) { inFavor++;//w ww . ja v a 2s. c om } total++; } final User mentor = application.getMentor(); final User applicant = application.getApplicant(); Date startDate = application.getStartDate(); LocalDate start = new LocalDate(startDate); LocalDate now = LocalDate.now(); final boolean have3DaysPassed = start.plusDays(3).isBefore(now); boolean accepted = false; if (have3DaysPassed) { if (applicant.getActivations().isEmpty()) { // If we managed to let 3 days pass without the member // getting // accepted, // check for mentor is no longer relevant, all we need to // know // is if a Senator // voted against if (total == 0) { accepted = true; } else { if (inFavor == 0) { accepted = false; } else { accepted = true; } } } else { accepted = false; } } else { // This really shouldn't happen, but don't resolve unactivated // users prior to 3 days if (!applicant.getActivations().isEmpty()) { return; } // If this method gets invoked earlier, however, then member // needs a mentor and 1 // vote in favor - otherwise do not resolve if (inFavor > 0 && mentor != null) { accepted = true; } else { return; } } if (accepted) { applicant.setMentor(application.getMentor()); applicant.setRank(Rank.TRIAL); applicant.setJoinDate(new Date()); applicant.setLoginCount(0); applicant.setLastAction(new Date()); userDAO.update(applicant); } joinVerdictDAO.deleteForApplication(application); joinApplicationDAO.delete(application); mailService.sendHTMLMail(applicant.getEMail(), "Result of your Tysan Clan Application", mailService.getJoinApplicationMail(application, accepted, inFavor, total)); logService.logUserAction(applicant, "Membership", "User has " + (accepted ? "been" : "not been") + " granted a trial membership"); if (accepted) { notificationService.notifyUser(applicant, "You are now a Trial Member"); dispatcher.dispatchEvent(new MemberStatusEvent( com.tysanclan.site.projectewok.entities.MembershipStatusChange.ChangeType.TRIAL_GRANTED, applicant)); } else { dispatcher.dispatchEvent(new MemberStatusEvent( com.tysanclan.site.projectewok.entities.MembershipStatusChange.ChangeType.TRIAL_DENIED, applicant)); } } }
From source file:config.TimeManipulation.java
License:Open Source License
/** * /*ww w . j a va 2s. c om*/ * @param LocalDate Date * @param String Time */ public DateTime EventDateTime(LocalDate Date, String Time) { if (Time == null) return null; char modifier = Time.charAt(Time.length() - 1); Time = Time.substring(0, Time.length() - 1); if (modifier == 'B') { Date.minusDays(1); } if (modifier == 'X') { Date.plusDays(1); } LocalTime timeformat = new LocalTime(Time); return Date.toDateTime(timeformat); }
From source file:courtscheduler.domain.DateConstraint.java
License:Apache License
public int[] findDateRange(LocalDate sdate, LocalDate edate) { int dayCount = Days.daysBetween(sdate, edate).getDays(); //System.out.println(dayCount); int[] days = new int[dayCount + 1]; for (int i = 0; i <= dayCount; i++) { Integer day = findDate(sdate.plusDays(i)); if (day != null) { days[i] = day;//from w w w .j av a 2 s .c o m } } return days; }
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 ww .j a v a2 s . com "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: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; }/*from ww w . jav a 2 s. co m*/ 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.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 www . j a v a 2 s . c om 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.hdu.zimmerbelegung.model.BelegungKopf.java
License:Open Source License
/** * pruefeKonsistenz//from ww w . ja v a2s . c o m * checks, if all guests, rooms, type of booking and timespan is not interrupted */ private void pruefeKonsistenz() throws Exception { Gast gast = getGast(); Zimmer zimmer = getZimmer(); LocalDate datum = getDatumVon(); BelegungArt art = getArt(); for (Belegung belegung : belegungen) { if (!belegung.getGast().equals(gast)) throw new Exception("Konsistenzfehler: Unterschiedliche Gste in Belegung [" + getId() + "/" + belegung.getId() + "]"); if (!belegung.getZimmer().equals(zimmer)) throw new Exception("Konsistenzfehler: Unterschiedliche Zimmer in Belegung [" + getId() + "/" + belegung.getId() + "]"); if (!belegung.getDatum().isEqual(datum)) throw new Exception("Konsistenzfehler: Zeitraum der Belegung ist nicht durchgngig [" + getId() + "/" + belegung.getId() + "]"); if (belegung.getArt() != art) throw new Exception("Konsistenzfehler: Art der Belegung ist nicht durchgngig [" + getId() + "/" + belegung.getId() + "]"); datum = datum.plusDays(1); } }