From 23d8c3b972d378f2f0129990343ffb3cc1ff02ae Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 4 Jan 2012 13:42:28 +0100 Subject: [PATCH] [Bug #1326] Fix issue calculating properly hours to allocate The issue was introduced in commit a998367bec9d6cf02729fa6283466a1f933a6e2b while trying to fix a different problem in interpolation function. The patch has been reverted and both issues fixed now. Once the patch was reverted, the number of remaining hours was wrong calculated as if it was 0 it returns the allocated hours instead of 0. FEA: ItEr76S04BugFixing --- .../planner/entities/StretchesFunctionTypeEnum.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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); }