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
32 lines
1.2 KiB
Java
32 lines
1.2 KiB
Java
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);
|
|
}
|
|
}
|