Base fixes and test harness
This commit is contained in:
@@ -74,9 +74,39 @@ enum MonthlyCheckInStore {
|
||||
}
|
||||
|
||||
static func setCompletionDate(_ completionDate: Date, for month: Date) {
|
||||
updateEntry(for: month) { entry in
|
||||
entry.completionTime = completionDate.timeIntervalSince1970
|
||||
let targetMonth = month.startOfMonth
|
||||
let targetKey = monthKey(for: targetMonth)
|
||||
var entries = loadEntries()
|
||||
var didChange = false
|
||||
|
||||
// Ensure the target month entry exists.
|
||||
var targetEntry = entries[targetKey] ?? MonthlyCheckInEntry(
|
||||
note: nil,
|
||||
rating: nil,
|
||||
mood: nil,
|
||||
completionTime: legacyCompletion(for: targetKey),
|
||||
createdAt: Date().timeIntervalSince1970
|
||||
)
|
||||
targetEntry.completionTime = completionDate.timeIntervalSince1970
|
||||
entries[targetKey] = targetEntry
|
||||
didChange = true
|
||||
|
||||
// Mark all previous pending entries as completed as well.
|
||||
for (key, entry) in entries {
|
||||
guard let entryMonth = monthFormatter.date(from: key)?.startOfMonth else { continue }
|
||||
guard entryMonth < targetMonth else { continue }
|
||||
guard entry.completionTime == nil else { continue }
|
||||
|
||||
var updated = entry
|
||||
let fallbackCompletion = min(entryMonth.endOfMonth, completionDate)
|
||||
updated.completionTime = fallbackCompletion.timeIntervalSince1970
|
||||
entries[key] = updated
|
||||
didChange = true
|
||||
}
|
||||
|
||||
guard didChange else { return }
|
||||
saveEntries(entries)
|
||||
persistLegacyMirrors(entries)
|
||||
}
|
||||
|
||||
static func latestCompletionDate() -> Date? {
|
||||
|
||||
Reference in New Issue
Block a user