1.1.0 feature work: Monthly Check-in, Charts, Goals, Share, Reviews
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,31 @@ class GoalsViewModel: ObservableObject {
|
||||
return NSDecimalNumber(decimal: current / goal.targetDecimal).doubleValue
|
||||
}
|
||||
|
||||
func isAchieved(_ goal: Goal) -> Bool {
|
||||
Self.isAchieved(progress: progress(for: goal))
|
||||
}
|
||||
|
||||
static func isAchieved(progress: Double) -> Bool {
|
||||
progress >= 0.999
|
||||
}
|
||||
|
||||
static func urgencyLevel(
|
||||
targetDate: Date?,
|
||||
isBehind: Bool,
|
||||
isAchieved: Bool,
|
||||
referenceDate: Date = Date()
|
||||
) -> GoalUrgencyLevel {
|
||||
guard let targetDate else { return .normal }
|
||||
guard !isAchieved else { return .normal }
|
||||
guard isBehind else { return .normal }
|
||||
|
||||
let daysUntilTarget = referenceDate.startOfDay.daysBetween(targetDate.startOfDay)
|
||||
if daysUntilTarget < 0 {
|
||||
return .critical
|
||||
}
|
||||
return .warning
|
||||
}
|
||||
|
||||
func totalValue(for goal: Goal) -> Decimal {
|
||||
if let accountId = goal.account?.safeId {
|
||||
return sourceRepository.sources
|
||||
@@ -288,3 +313,9 @@ struct GoalPaceStatus {
|
||||
let isBehind: Bool
|
||||
let statusText: String
|
||||
}
|
||||
|
||||
enum GoalUrgencyLevel: Equatable {
|
||||
case normal
|
||||
case warning
|
||||
case critical
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user