BP-833, fix adding start of day for longer phases
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 be63eb2..abf0659 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
@@ -1557,18 +1557,24 @@
currentDate);
if (lsFittingDurationsEndingAtStart != null && !lsFittingDurationsEndingAtStart.isEmpty()) {
for (StandbyDuration dur : lsFittingDurationsEndingAtStart) {
- int startWeekDayInt = DateHelper.getDayOfWeek(currentDate);
- int endDurationWeekDayInt = dur.getValidDayTo();
-
- int coveredDays = DateHelper.calculateDifferenceOfDays(startWeekDayInt, endDurationWeekDayInt,
- dur.getValidFrom(), dur.getValidTo());
- if (coveredDays != 0) {
- // only durations should be added that start at least one day before and their
- // ending at the phase start
+ int currentWeekDayInt = DateHelper.getDayOfWeek(currentDate);
+ int startDurationWeekDayInt = dur.getValidDayFrom();
+ // do not use durations that start at the current day because they will be found
+ // in the normal calculation.
+ if (startDurationWeekDayInt != currentWeekDayInt) {
StandbyDuration tmpDuration = dur.copy();
- tmpDuration.setValidFrom(DateHelper.getStartOfDay(tmpDuration.getValidFrom()));
+ // set start to current day 00:00 because duration comes from day earlier.
+ tmpDuration.setValidFrom(DateHelper.getStartOfDay(tmpDuration.getValidTo()));
tmpDuration.setValidDayFrom(DateHelper.getDayOfWeek(currentDate));
- tmpDuration.setValidDayTo(DateHelper.getDayOfWeek(currentDate));
+ int endDurationWeekDayInt = dur.getValidDayTo();
+ if (endDurationWeekDayInt == currentWeekDayInt) {
+ // if durations ends current day use the end of duration
+ tmpDuration.setValidDayTo(DateHelper.getDayOfWeek(currentDate));
+ } else {
+ // else use the end of day.
+ tmpDuration.setValidDayTo(DateHelper.getDayOfWeek(currentDate));
+ tmpDuration.setValidTo(DateHelper.getEndOfDay(currentDate));
+ }
lsFittingDurations.add(tmpDuration);
}
}