DateMidnight startDate = formatter.parseDateTime(getParamValue(req, bookings, "startDate")).toDateMidnight(); DateMidnight endDate = formatter.parseDateTime(getParamValue(req, bookings, "endDate")).toDateMidnight(); String copyType = getParamValue(req, bookings, "copyType");  if (startDate.isAfter(endDate)) throw new BookingException("The start date (" + startDate.toString("MMMM d, yyyy") + ") is after the end date (" + endDate.toString("MMMM d, yyyy") + ").");  Period period = null; DateMidnight date = null;  if (WEEKLY.equals(copyType)) {  period = new Period(0, 0, 1, 0, 0, 0, 0, 0);   int cdow = bookings.getDate().getDayOfWeek(); int sdow = startDate.getDayOfWeek(); date = startDate.plus(new Period(0,0,0, 7+cdow-sdow, 0, 0, 0, 0)); } else if (DAILY.equals(copyType)) { period = new Period(0,0,0,1,0,0,0,0); date = startDate; } else { throw new BookingException("A copy operation was requested without providing a valid copy type."); }  while (!date.isAfter(endDate)) { bookings.gotoDate(date); if (bookings.getBooking() == null) bookings.setBooking(booking); date = date.plus(period); }  bookings.gotoDate(originalDate);
DateMidnight startDate = formatter.parseDateTime(getParamValue(req, bookings, "startDate")).toDateMidnight(); DateMidnight endDate = formatter.parseDateTime(getParamValue(req, bookings, "endDate")).toDateMidnight(); String copyType = getParamValue(req, bookings, "copyType");  if (startDate.isAfter(endDate)) throw new BookingException("The start date (" + startDate.toString("MMMM d, yyyy") + ") is after the end date (" + endDate.toString("MMMM d, yyyy") + ").");  Period period; DateMidnight date;  if (WEEKLY.equals(copyType)) {  period = new Period(0, 0, 1, 0, 0, 0, 0, 0);   int cdow = bookings.getDate().getDayOfWeek(); int sdow = startDate.getDayOfWeek(); date = startDate.plus(new Period(0, 0, 0, 7 + cdow - sdow, 0, 0, 0, 0)); } else if (DAILY.equals(copyType)) { period = new Period(0, 0, 0, 1, 0, 0, 0, 0); date = startDate; } else { throw new BookingException("A copy operation was requested without providing a valid copy type."); }  while (!date.isAfter(endDate)) { bookings.gotoDate(date); if (bookings.getBooking() == null) bookings.setBooking(booking); date = date.plus(period); }  bookings.gotoDate(originalDate);
    private void copyBooking(BookingModel bookings, String remoteUser, HttpServletRequest req)    {        DateTimeFormat format = DateTimeFormat.getInstance();        DateTimeFormatter formatter = format.forPattern("dd-MMM-yyyy");                // Get the current booking.        Booking booking = bookings.getBooking();        DateMidnight originalDate = bookings.getDate();                try        {	        DateMidnight startDate = formatter.parseDateTime(getParamValue(req, bookings, "startDate")).toDateMidnight();	        DateMidnight endDate = formatter.parseDateTime(getParamValue(req, bookings, "endDate")).toDateMidnight();	        String copyType = getParamValue(req, bookings, "copyType");        	        if (startDate.isAfter(endDate))	            throw new BookingException("The start date (" + startDate.toString("MMMM d, yyyy") + ") is after the end date (" + endDate.toString("MMMM d, yyyy") + ").");	        	        Period period = null;	        DateMidnight date = null;	        	        if (WEEKLY.equals(copyType))	        {	            // Set the period to one week.	            period = new Period(0, 0, 1, 0, 0, 0, 0, 0);	            	            // Set the startDate first day that is the same as the current date's day.	            int cdow = bookings.getDate().getDayOfWeek();	            int sdow = startDate.getDayOfWeek();	            date = startDate.plus(new Period(0,0,0, 7+cdow-sdow, 0, 0, 0, 0));	        }	        else if (DAILY.equals(copyType))	        {	            period = new Period(0,0,0,1,0,0,0,0);	            date = startDate;	        }	        else	        {	            throw new BookingException("A copy operation was requested without providing a valid copy type.");	        }	        	        while (!date.isAfter(endDate))	        {	            bookings.gotoDate(date);	            if (bookings.getBooking() == null)	                bookings.setBooking(booking);	            date = date.plus(period);	        }	        	        bookings.gotoDate(originalDate);        }        catch (Exception e)        {            throw new BookingException(e.getMessage());        }    }