From 65b24f8099512e958fab969477fd37945f1dee7f Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Wed, 11 Jan 2012 16:25:59 +0100 Subject: [PATCH] Bug #1329: Fix issue calculating properly end date of stretches The problem was that when a task finishes in a complete day, that means, task end date is the next day with zero effort. In this situation, the stretches calculation was enlarging 1 day more the task itself which causes the issue reported in this bug. FEA: ItEr76S04BugFixing --- .../business/planner/entities/ResourceAllocation.java | 3 ++- .../libreplan/business/planner/entities/Stretch.java | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java index 6f6b012db..5c2eab504 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/ResourceAllocation.java @@ -1922,7 +1922,8 @@ public abstract class ResourceAllocation extends return null; } DayAssignment lastAssignment = assignments.get(assignments.size() - 1); - return lastAssignment.getDay().plusDays(1); + return IntraDayDate.create(lastAssignment.getDay(), + lastAssignment.getDuration()).asExclusiveEnd(); } public boolean isAlreadyFinishedBy(LocalDate date) { diff --git a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Stretch.java b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Stretch.java index 95d3be414..6faf01095 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Stretch.java +++ b/libreplan-business/src/main/java/org/libreplan/business/planner/entities/Stretch.java @@ -22,6 +22,7 @@ package org.libreplan.business.planner.entities; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -46,16 +47,17 @@ public class Stretch { public static LocalDate getDateByLengthProportion( ResourceAllocation allocation, BigDecimal lengthProportion) { int allocationDuration = Days.daysBetween(allocation.getStartDate(), - allocation.getEndDate()).getDays(); - int days = lengthProportion.multiply( - BigDecimal.valueOf(allocationDuration)).intValue(); + allocation.getIntraDayEndDate().asExclusiveEnd()).getDays(); + int days = lengthProportion + .multiply(BigDecimal.valueOf(allocationDuration)) + .setScale(0, RoundingMode.HALF_UP).intValue(); return allocation.getStartDate().plusDays(days); } public static BigDecimal getLengthProportionByDate( ResourceAllocation allocation, LocalDate date) { int allocationDuration = Days.daysBetween(allocation.getStartDate(), - allocation.getEndDate()).getDays(); + allocation.getIntraDayEndDate().asExclusiveEnd()).getDays(); int days = Days.daysBetween(allocation.getStartDate(), date).getDays(); return daysProportion(days, allocationDuration); }