diff --git a/FabianUtil.java b/FabianUtil.java index 2b75423..cf8487a 100644 --- a/FabianUtil.java +++ b/FabianUtil.java @@ -87,15 +87,27 @@ public class FabianUtil { public void logIf() { - if (counter.remainder(logDistance).signum() == 0) { + if (counter.remainder(logDistance).signum() == 0 || isBored()) { log(); } } + private boolean isBored() { + ZonedDateTime time = lastLoggedAt == null ? startTime : lastLoggedAt; + return time.until(ZonedDateTime.now(), ChronoUnit.SECONDS) >= timeLogDistance; + } + + public void log() { Duration timePassed = getTimePassed(); System.out.println(counter + " Stück erledigt. " + formatDuration(timePassed) + " vergangen."); + updateLastLoggedAt(); + } + + + protected void updateLastLoggedAt() { + lastLoggedAt = ZonedDateTime.now(); } @@ -163,6 +175,7 @@ public class FabianUtil { String counterPrint = total.compareTo(BigDecimal.TEN) >= 0 ? formatNumber(counter) : counter.toString(); System.out.println(counterPrint + " Stück von " + total + " (" + PERCENTAGE_FORMAT.format(percentage) + " %) erledigt. " + formatDuration(timePassed) + " vergangen" + remainingTimePart + "."); + updateLastLoggedAt(); } }