Fix widget gap: forward-fill months and use reference month date for batch update
BatchUpdateView now accepts a saveDate parameter. When saving from a past-month check-in, the call site passes referenceDate.endOfMonth so snapshots are dated within the correct month instead of today. For the current month, Date() is used. Widget forward-fills missing month buckets (trend and category series) using the most recent earlier month's value, preventing gaps when a check-in is done in the following month. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -264,7 +264,12 @@ struct InvestmentWidgetProvider: TimelineProvider {
|
||||
}
|
||||
let monthFormatter = DateFormatter()
|
||||
monthFormatter.dateFormat = "MMM"
|
||||
trendPoints = months.map { monthlyTotals[$0] ?? .zero }
|
||||
trendPoints = months.map { month in
|
||||
if let value = monthlyTotals[month] { return value }
|
||||
// Forward-fill: use the most recent earlier month's value
|
||||
let previous = sortedMonths.last { $0.0 < month }
|
||||
return previous?.1 ?? .zero
|
||||
}
|
||||
trendLabels = months.map { monthFormatter.string(from: $0) }
|
||||
}
|
||||
|
||||
@@ -307,7 +312,13 @@ struct InvestmentWidgetProvider: TimelineProvider {
|
||||
|
||||
let categoryEvolution: [CategorySeries] = categoryTotalsData.prefix(4).map { category in
|
||||
let monthMap = categoryMonthlyTotals[category.id] ?? [:]
|
||||
let points = months.map { monthMap[$0] ?? .zero }
|
||||
let sortedCategoryMonths = monthMap.map { ($0.key, $0.value) }.sorted { $0.0 < $1.0 }
|
||||
let points = months.map { month -> Decimal in
|
||||
if let value = monthMap[month] { return value }
|
||||
// Forward-fill: use the most recent earlier month's value
|
||||
let previous = sortedCategoryMonths.last { $0.0 < month }
|
||||
return previous?.1 ?? .zero
|
||||
}
|
||||
return CategorySeries(
|
||||
id: category.id,
|
||||
name: category.name,
|
||||
|
||||
Reference in New Issue
Block a user