App 2.20.0: lease mileage allowance on the Overview
Vehicle info shows the km allowed by today (40,000 km over four years from 2023-05-01, evenly per day) and the odometer against it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.evsuite.abrp;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
/**
|
||||
* The lease's mileage allowance: 40,000 km over four years from 1 May 2023, accruing evenly per
|
||||
* day. The Overview's Vehicle info card shows what is allowed by today and how far the odometer
|
||||
* is above or below it. Pure Java, so it is unit-tested.
|
||||
*/
|
||||
final class LeaseAllowance {
|
||||
|
||||
static final LocalDate START = LocalDate.of(2023, 5, 1);
|
||||
static final LocalDate END = START.plusYears(4);
|
||||
static final double TOTAL_KM = 40_000d;
|
||||
|
||||
private LeaseAllowance() {}
|
||||
|
||||
/** Kilometres allowed by {@code today}: none before the start, all of them from the end on. */
|
||||
static double allowedKm(LocalDate today) {
|
||||
long total = ChronoUnit.DAYS.between(START, END);
|
||||
long elapsed = Math.max(0L, Math.min(total, ChronoUnit.DAYS.between(START, today)));
|
||||
return TOTAL_KM * elapsed / total;
|
||||
}
|
||||
|
||||
/** Odometer minus allowance: positive over, negative under; null when the odometer is unread. */
|
||||
static Double differenceKm(Float odometerKm, LocalDate today) {
|
||||
if (odometerKm == null || !Float.isFinite(odometerKm)) return null;
|
||||
return odometerKm - allowedKm(today);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user