Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1.  
  2.     @Override
  3.     public int getDayCountInRangeOfBox(int boxID,int day,Date from,Date end) {
  4.         LOG.info("Enter getDayCountInRangeOfBox "+ boxID + " " + day + " " + from + " " + end);
  5.         int counter =0;
  6.  
  7.         // find all Bookings which are in the Range
  8.         List<Booking> bookingsList = findBookingsWithIdAndDateRange(boxID,from,end);
  9.  
  10.         // calculate it for all Bookings and return the amount of Monday
  11.         for(Booking b :bookingsList) {
  12.             counter += countWeekdayOfBooking(b,day);
  13.         }
  14.  
  15.         return counter;
  16.     }
  17.  
  18.     // calculate the Amount of days
  19.     public int countWeekdayOfBooking(Booking booking,int day) {
  20.         LOG.info("Enter countWeekdayOfBooking " +booking + " " + day);
  21.  
  22.         //   get Begin and End of Booking
  23.         LocalDate currentDay = booking.getFromDate().toLocalDate();
  24.         LocalDate end = booking.getToDate().toLocalDate();
  25.  
  26.         int counter = 0;
  27.         Calendar calendar = Calendar.getInstance();
  28.         Date currentDate;
  29.  
  30.         for(; currentDay.isBefore(end.plusDays(1)); currentDay = currentDay.plusDays(1))
  31.         {
  32.  
  33.             // transfrom to date
  34.             currentDate = java.sql.Date.valueOf(currentDay);
  35.  
  36.             calendar.setTime(currentDate);
  37.             int currentWeekDay = calendar.get(Calendar.DAY_OF_WEEK);
  38.  
  39.  
  40.             if(currentWeekDay == day)
  41.             {
  42.                 counter ++;
  43.             }
  44.         }
  45.  
  46.  
  47.         return counter;
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement