Fix check-in progress bar always showing empty after completing check-in

Previous logic measured elapsed days from lastCompletionDate to nextCheckInDate,
so completing a check-in today reset the bar to 0/8 days instead of showing
how far through the full monthly period we are.

New logic: the bar represents the full interval (e.g. 1 month) ending at
nextCheckInDate, starting from nextCheckInDate minus that interval.
Today (Feb 20) with next check-in Feb 28 now shows ~74% progress
(23 of 31 days elapsed since Jan 28) instead of 0%.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
alexandrev-tibco
2026-02-20 22:44:22 +01:00
parent 472342fa67
commit b6314db314
@@ -31,12 +31,15 @@ struct MonthlyCheckInView: View {
} }
private var checkInProgress: Double { private var checkInProgress: Double {
guard let last = lastCompletionDate, guard let nextDate = nextCheckInDate,
let nextDate = nextCheckInDate else { return 1 } let periodStart = Calendar.current.date(
let totalDays = Double(max(1, last.startOfDay.daysBetween(nextDate.startOfDay))) byAdding: .month,
guard totalDays > 0 else { return 1 } value: -checkInIntervalMonths,
let elapsedDays = Double(last.startOfDay.daysBetween(Date())) to: nextDate
return min(max(elapsedDays / totalDays, 0), 1) ) else { return 1 }
let totalDays = Double(max(1, periodStart.startOfDay.daysBetween(nextDate.startOfDay)))
let elapsedDays = Double(max(0, periodStart.startOfDay.daysBetween(Date().startOfDay)))
return min(elapsedDays / totalDays, 1)
} }
private var checkInIntervalMonths: Int { private var checkInIntervalMonths: Int {