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 {
|
private var checkInProgress: Double {
|
||||||
guard let nextDate = nextCheckInDate,
|
guard let nextDate = nextCheckInDate else { return 1 }
|
||||||
let periodStart = Calendar.current.date(
|
// Period starts at the first day of the month that opens the interval.
|
||||||
byAdding: .month,
|
// e.g. monthly → Feb 1; quarterly → Jan 1 (3 months ending Mar 31)
|
||||||
value: -checkInIntervalMonths,
|
let periodStart = nextDate.adding(months: -(checkInIntervalMonths - 1)).startOfMonth
|
||||||
to: nextDate
|
|
||||||
) else { return 1 }
|
|
||||||
let totalDays = Double(max(1, periodStart.startOfDay.daysBetween(nextDate.startOfDay)))
|
let totalDays = Double(max(1, periodStart.startOfDay.daysBetween(nextDate.startOfDay)))
|
||||||
let elapsedDays = Double(max(0, periodStart.startOfDay.daysBetween(Date().startOfDay)))
|
let elapsedDays = Double(max(0, periodStart.startOfDay.daysBetween(Date().startOfDay)))
|
||||||
return min(elapsedDays / totalDays, 1)
|
return min(elapsedDays / totalDays, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user