From e3ec0ddb253d85c22692cf1cb25eaf238d4a7fd5 Mon Sep 17 00:00:00 2001 From: alexandrev-tibco Date: Fri, 20 Feb 2026 22:45:59 +0100 Subject: [PATCH] Fix progress bar period to start at first day of interval month MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Views/Dashboard/MonthlyCheckInView.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/PortfolioJournal/Views/Dashboard/MonthlyCheckInView.swift b/PortfolioJournal/Views/Dashboard/MonthlyCheckInView.swift index 9b715f1..d362c59 100644 --- a/PortfolioJournal/Views/Dashboard/MonthlyCheckInView.swift +++ b/PortfolioJournal/Views/Dashboard/MonthlyCheckInView.swift @@ -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)