Fix progress bar period to start at first day of interval month
Period now starts at startOfMonth of the first month in the interval, not 30 days before the deadline. For monthly: Feb 1 → Feb 28. For quarterly: Jan 1 → Mar 31. Formula: startOfMonth(nextDate - (interval-1) months). Feb 20 with next check-in Feb 28: 19/27 days ≈ 70% instead of 0%. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,12 +31,10 @@ struct MonthlyCheckInView: View {
|
||||
}
|
||||
|
||||
private var checkInProgress: Double {
|
||||
guard let nextDate = nextCheckInDate,
|
||||
let periodStart = Calendar.current.date(
|
||||
byAdding: .month,
|
||||
value: -checkInIntervalMonths,
|
||||
to: nextDate
|
||||
) else { return 1 }
|
||||
guard let nextDate = nextCheckInDate else { return 1 }
|
||||
// Period starts at the first day of the month that opens the interval.
|
||||
// e.g. monthly → Feb 1; quarterly → Jan 1 (3 months ending Mar 31)
|
||||
let periodStart = nextDate.adding(months: -(checkInIntervalMonths - 1)).startOfMonth
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user