- handle negative endTimeOffset

- deduplicated code
This commit is contained in:
2025-08-08 14:58:37 +02:00
parent e6ef9ec87f
commit 971bf22495

View File

@@ -367,12 +367,11 @@ public class LoadingBar extends AbstractProgressBar {
private long getMinLunchDuration(int endTimeOffset) {
if (endTimeOffset == 0) {
if (endTimeOffset <= 0) {
return MIN_LUNCH_DURATION;
}
long totalDuration = MAX_NUMBER_WORK_MINS + endTimeOffset;
long effectiveLunchDuration = totalDuration - MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH;
return getMinLunchDuration(effectiveLunchDuration);
return getMinLunchDuration(totalDuration);
}
@@ -381,12 +380,12 @@ public class LoadingBar extends AbstractProgressBar {
return MIN_LUNCH_DURATION;
}
long totalDuration = getStartTime().until(manualEndTime, ChronoUnit.MINUTES);
long effectiveLunchDuration = totalDuration - MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH;
return getMinLunchDuration(effectiveLunchDuration);
return getMinLunchDuration(totalDuration);
}
private long getMinLunchDuration(long effectiveLunchDuration) {
private long getMinLunchDuration(long precalculatedTotalDuration) {
long effectiveLunchDuration = precalculatedTotalDuration - MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH;
if (effectiveLunchDuration < 0) {
effectiveLunchDuration = 0;
}