DateAndHour endTime) {
ResourceCalendar calendar = resource.getCalendar();
List<DayAssignment> result = new ArrayList<DayAssignment>();
LocalDate date = endTime.getDate();
EffortDuration totalIntended = hours(resourceAllocation
.getIntendedTotalHours());
// Generate last day assignment
PartialDay firstDay = new PartialDay(IntraDayDate.startOfDay(date),
IntraDayDate.create(date, hours(endTime.getHour())));
EffortDuration effortCanAllocate = min(totalIntended,
calendar.asDurationOn(firstDay, ONE_RESOURCE_PER_DAY));
if (effortCanAllocate.compareTo(zero()) > 0) {
DayAssignment dayAssignment = createDayAssignment(
resourceAllocation, resource, date, effortCanAllocate);
totalIntended = totalIntended.minus(addDayAssignment(result,
dayAssignment));
}
// Generate rest of day assignments
for (date = date.minusDays(1); totalIntended.compareTo(zero()) > 0; date = date
.minusDays(1)) {
EffortDuration duration = min(totalIntended, calendar.asDurationOn(
PartialDay.wholeDay(date), ONE_RESOURCE_PER_DAY));
DayAssignment dayAssigment = createDayAssignment(
resourceAllocation, resource, date, duration);
totalIntended = totalIntended.minus(addDayAssignment(result,
dayAssigment));