140 lines
4.9 KiB
Java
140 lines
4.9 KiB
Java
package de.szimnau;
|
|
|
|
import de.szimnau.tools.CommonTools;
|
|
import de.szimnau.tools.FormatTools;
|
|
import java.io.IOException;
|
|
import java.time.LocalTime;
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.util.*;
|
|
import de.szimnau.tools.LoadingBarCliTools;
|
|
|
|
import static de.szimnau.tools.CommonTools.print;
|
|
|
|
|
|
public class LoadingBar extends AbstractProgressBar {
|
|
|
|
public static final long MAX_NUMBER_WORK_MINS = 8L * CommonTools.MINS_PER_HOUR;
|
|
public static final int MIN_LUNCH_DURATION = 30;
|
|
public static final LocalTime LATEST_LUNCH_TIME = LocalTime.of(13, 30);
|
|
public static final int MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH = 6 * CommonTools.MINS_PER_HOUR;
|
|
protected static final long DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH = 5L * CommonTools.MINS_PER_HOUR;
|
|
|
|
|
|
protected LoadingBar(LocalTime startTime) {
|
|
super(startTime);
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
if (args.length == 0) {
|
|
LoadingBarCliTools.askParametersAndRun(LoadingBar::new);
|
|
} else {
|
|
LoadingBarCliTools.parseParametersAndRun(args, LoadingBar::new);
|
|
}
|
|
}
|
|
|
|
|
|
public boolean hasMittagspauseArrived() {
|
|
return hasMittagspauseArrived(false);
|
|
}
|
|
|
|
|
|
public boolean hasMittagspauseArrived(boolean debugWithPassedMinutesZero) {
|
|
return getPassedMinutes(debugWithPassedMinutesZero) < DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH;
|
|
}
|
|
|
|
|
|
public void initMittagspause() {
|
|
LocalTime defaultEndTime = getStartTime().plusMinutes(DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH);
|
|
realInitMittagspause(defaultEndTime);
|
|
}
|
|
|
|
|
|
public void initMittagspause(int endTimeOffset) {
|
|
LocalTime offsetEndTime = getStartTime().plusMinutes(DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH + endTimeOffset);
|
|
realInitMittagspause(offsetEndTime);
|
|
}
|
|
|
|
|
|
public void initMittagspause(LocalTime manualEndTime) {
|
|
LocalTime effectiveEndTime = manualEndTime != null ? manualEndTime : getStartTime().plusMinutes(DEFAULT_NUMBER_WORK_MINS_BEFORE_LUNCH);
|
|
realInitMittagspause(effectiveEndTime);
|
|
}
|
|
|
|
|
|
private void realInitMittagspause(LocalTime theoreticalEndTime) {
|
|
setEndTime(theoreticalEndTime.isAfter(LATEST_LUNCH_TIME) ? LATEST_LUNCH_TIME : theoreticalEndTime);
|
|
}
|
|
|
|
|
|
public void initZapfenstreich() {
|
|
LocalTime trueEndTime = getStartTime().plusMinutes(MAX_NUMBER_WORK_MINS + MIN_LUNCH_DURATION);
|
|
realInitZapfenstreich(MIN_LUNCH_DURATION, trueEndTime);
|
|
}
|
|
|
|
|
|
public void initZapfenstreich(Integer manualLunchDuration) {
|
|
initZapfenstreich(manualLunchDuration, 0);
|
|
}
|
|
|
|
|
|
public void initZapfenstreich(Integer manualLunchDuration, int endTimeOffset) {
|
|
long minLunchDuration = getMinLunchDuration(endTimeOffset);
|
|
long realLunchDuration = getRealLunchDuration(manualLunchDuration, minLunchDuration);
|
|
LocalTime trueEndTime = getStartTime().plusMinutes(MAX_NUMBER_WORK_MINS + realLunchDuration + endTimeOffset);
|
|
realInitZapfenstreich(realLunchDuration, trueEndTime);
|
|
}
|
|
|
|
|
|
public void initZapfenstreich(Integer manualLunchDuration, LocalTime manualEndTime) {
|
|
LocalTime trueEndTime = manualEndTime;
|
|
long minLunchDuration = getMinLunchDuration(trueEndTime);
|
|
long realLunchDuration = getRealLunchDuration(manualLunchDuration, minLunchDuration);
|
|
if (trueEndTime == null) {
|
|
trueEndTime = getStartTime().plusMinutes(MAX_NUMBER_WORK_MINS + realLunchDuration);
|
|
}
|
|
realInitZapfenstreich(realLunchDuration, trueEndTime);
|
|
}
|
|
|
|
|
|
private long getMinLunchDuration(int endTimeOffset) {
|
|
if (endTimeOffset <= 0) {
|
|
return MIN_LUNCH_DURATION;
|
|
}
|
|
long totalDuration = MAX_NUMBER_WORK_MINS + endTimeOffset;
|
|
return getMinLunchDuration(totalDuration);
|
|
}
|
|
|
|
|
|
private long getMinLunchDuration(LocalTime manualEndTime) {
|
|
if (manualEndTime == null) {
|
|
return MIN_LUNCH_DURATION;
|
|
}
|
|
long totalDuration = getStartTime().until(manualEndTime, ChronoUnit.MINUTES);
|
|
return getMinLunchDuration(totalDuration);
|
|
}
|
|
|
|
|
|
private long getMinLunchDuration(long precalculatedTotalDuration) {
|
|
long effectiveLunchDuration = precalculatedTotalDuration - MAX_NUMBER_WORK_MINS_WITHOUT_LUNCH;
|
|
if (effectiveLunchDuration < 0) {
|
|
effectiveLunchDuration = 0;
|
|
}
|
|
return Math.min(effectiveLunchDuration, MIN_LUNCH_DURATION);
|
|
}
|
|
|
|
|
|
private long getRealLunchDuration(Integer manualLunchDuration, long minLunchDuration) {
|
|
return manualLunchDuration != null && manualLunchDuration >= minLunchDuration ? manualLunchDuration : minLunchDuration;
|
|
}
|
|
|
|
|
|
private void realInitZapfenstreich(long effectiveLunchDuration, LocalTime effectiveEndTime) {
|
|
if (effectiveLunchDuration > 0) {
|
|
var totalWorkTime = LocalTime.MIDNIGHT.plusMinutes(getStartTime().until(effectiveEndTime, ChronoUnit.MINUTES) - effectiveLunchDuration);
|
|
print("Arbeitszeit: " + FormatTools.TIME_FORMATTER.format(totalWorkTime) + "; ");
|
|
}
|
|
setEndTime(effectiveEndTime);
|
|
}
|
|
}
|