BP-833, fix using wrong duration at same date
diff --git a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/PlanningController.java b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/PlanningController.java
index c60f9bf..16d673c 100644
--- a/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/PlanningController.java
+++ b/oKBereitschaftsplanungBackend/src/main/java/org/eclipse/openk/sp/controller/planning/PlanningController.java
@@ -191,6 +191,7 @@
 

 			// temporal date for calculation

 			Date tmpDate = validFrom;

+			Date nextStartDateOfPhase = null;

 			StandbyGroup group = standbyGroupRepository.findOne(standbyBlueprintDto.getStandbyGroupId());

 			StandbyDuration firstDuration = this.getFittingDurationOfGroup(group, validFrom);

 			if (firstDuration != null) {

@@ -208,20 +209,19 @@
 				if (lsDur != null && !lsDur.isEmpty()) {

 					duration = lsDur.get(lsDur.size() - 1);

 

-					// get days between duration start and end

+					// current week day

+					int tempDateDay = DateHelper.getDayOfWeek(tmpDate);

+

+					// get days between duration start and duration end

 					int differenceOfDurationDays = DateHelper.calculateDifferenceOfDays(duration.getValidDayFrom(),

 							duration.getValidDayTo(), duration.getValidFrom(), duration.getValidTo());

 

-					Date endDurDate = DateHelper.addDaysToDate(tmpDate, differenceOfDurationDays);

-					endDurDate = DateHelper.getDateWithTime(endDurDate, duration.getValidTo());

+					// get days between duration start and the current date (tmpDate)

+					int differenceOfTempDateAndDurStart = DateHelper.calculateDifferenceOfDays(

+							duration.getValidDayFrom(), tempDateDay, duration.getValidFrom(), tmpDate);

 

-					if (differenceOfDurationDays == 0) {

-						differenceOfDays = DateHelper.calculateDifferenceOfDays(DateHelper.getDayOfWeek(tmpDate),

-								duration.getValidDayTo(), tmpDate, duration.getValidTo());

-					} else {

-						differenceOfDays = DateHelper.calculateDifferenceOfDays(DateHelper.getDayOfWeek(tmpDate),

-								DateHelper.getDayOfWeek(endDurDate), tmpDate, endDurDate);

-					}

+					// reduce duration slot with the starting difference

+					differenceOfDays = differenceOfDurationDays - differenceOfTempDateAndDurStart;

 

 					Date startOfDuration = DateHelper.getDateWithTime(tmpDate, duration.getValidFrom());

 					Date endOfDuration = DateHelper.addDaysToDate(tmpDate, differenceOfDays);

@@ -236,6 +236,8 @@
 									tmpDur.getValidTo());

 							endOfDuration = DateHelper.addDaysToDate(tmpDate, differenceOfDays);

 							endOfDuration = DateHelper.getDateWithTime(endOfDuration, tmpDur.getValidTo());

+						} else {

+							LOGGER.debug("Keine Duration für den Tag : " + startOfDuration + " gefunden.");

 						}

 					}

 

@@ -253,18 +255,23 @@
 								phase++;

 								LOGGER.debug("Add phase " + phase);

 								resultMap.put(phase,

-										new PlanningPhaseDto(startOfDuration, endOfDuration, lsUserInGroup));

+										new PlanningPhaseDto(dto.getEndDate(), endOfDuration, lsUserInGroup));

+

 							}

 						} else {

 							LOGGER.debug("Add phase " + phase);

 							resultMap.put(phase, new PlanningPhaseDto(startOfDuration, endOfDuration, lsUserInGroup));

 						}

+					} else {

+						LOGGER.debug("Keine Gruppe gefunden!");

 					}

 

+					if (differenceOfDays == 0) {

+						// add at least one day

+						differenceOfDays = 1;

+					}

 					tmpDate = DateHelper.addDaysToDate(tmpDate, differenceOfDays);

-

 				}

-

 			}

 			this.logPhases(resultMap);

 			return resultMap;