diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/StretchesFunctionTypeEnum.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/StretchesFunctionTypeEnum.java index 522f936ea..037fc6c17 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/StretchesFunctionTypeEnum.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/StretchesFunctionTypeEnum.java @@ -85,13 +85,22 @@ public enum StretchesFunctionTypeEnum { // must be distributed. int[] assignedHours = getAssignedHours(allocation, startInclusive, newEndDate); int[] remindingHours = distributeRemainder(allocation, startInclusive, totalHours, assignedHours); - allocateDaysFrom(allocation, asEffortDuration(remindingHours), + int[] hoursToAllocate = sum(assignedHours, remindingHours); + allocateDaysFrom(allocation, asEffortDuration(hoursToAllocate), startInclusive); assignedHours = getAssignedHours(allocation, startInclusive, newEndDate); Validate.isTrue(sum(assignedHours) == totalHours); } + private int[] sum(int[] assignedHours, int[] remindingHours) { + Validate.isTrue(assignedHours.length == remindingHours.length); + for (int i = 0; i < assignedHours.length; i++) { + assignedHours[i] += remindingHours[i]; + } + return assignedHours; + } + private int[] getAssignedHours(ResourceAllocation allocation, LocalDate startInclusive, LocalDate endExclusive) { @@ -127,7 +136,7 @@ public enum StretchesFunctionTypeEnum { int[] reallyAssigned) { final int remainder = totalHours - sum(reallyAssigned); if (remainder == 0) { - return reallyAssigned; + return new int[reallyAssigned.length]; } return distributeRemainder(reallyAssigned, remainder); }