Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public int getDayCountInRangeOfBox(int boxID,int day,Date from,Date end) {
- LOG.info("Enter getDayCountInRangeOfBox "+ boxID + " " + day + " " + from + " " + end);
- int counter =0;
- // find all Bookings which are in the Range
- List<Booking> bookingsList = findBookingsWithIdAndDateRange(boxID,from,end);
- // calculate it for all Bookings and return the amount of Monday
- for(Booking b :bookingsList) {
- counter += countWeekdayOfBooking(b,day);
- }
- return counter;
- }
- // calculate the Amount of days
- public int countWeekdayOfBooking(Booking booking,int day) {
- LOG.info("Enter countWeekdayOfBooking " +booking + " " + day);
- // get Begin and End of Booking
- LocalDate currentDay = booking.getFromDate().toLocalDate();
- LocalDate end = booking.getToDate().toLocalDate();
- int counter = 0;
- Calendar calendar = Calendar.getInstance();
- Date currentDate;
- for(; currentDay.isBefore(end.plusDays(1)); currentDay = currentDay.plusDays(1))
- {
- // transfrom to date
- currentDate = java.sql.Date.valueOf(currentDay);
- calendar.setTime(currentDate);
- int currentWeekDay = calendar.get(Calendar.DAY_OF_WEEK);
- if(currentWeekDay == day)
- {
- counter ++;
- }
- }
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement