Skip to content

Commit

Permalink
fix for adding carbs in past/future
Browse files Browse the repository at this point in the history
- allows to add carbs in past or future
- allows to add FPU

only use createdAt attribute
  • Loading branch information
avouspierre committed Apr 7, 2024
1 parent 6fb3691 commit f5d301e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions FreeAPS/Sources/APS/Storage/CarbsStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
} else { useDate = useDate.addingTimeInterval(interval.minutes.timeInterval) }

let eachCarbEntry = CarbsEntry(
id: UUID().uuidString, createdAt: entries.last?.createdAt ?? Date(),
id: UUID().uuidString, createdAt: useDate,
carbs: equivalent, fat: 0, protein: 0, note: nil,
enteredBy: CarbsEntry.manual, isFPU: true,
fpuID: fpuID
Expand All @@ -92,7 +92,7 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
// Save the array
if carbEquivalents > 0 {
self.storage.transaction { storage in
storage.append(futureCarbArray, to: file, uniqBy: \.createdAt)
storage.append(futureCarbArray, to: file, uniqBy: \.id)
uniqEvents = storage.retrieve(file, as: [CarbsEntry].self)?
.filter { $0.createdAt.addingTimeInterval(1.days.timeInterval) > Date() }
.sorted { $0.createdAt > $1.createdAt } ?? []
Expand Down
2 changes: 1 addition & 1 deletion FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extension AddCarbs {
carbsStorage.storeCarbs(
[CarbsEntry(
id: UUID().uuidString,
createdAt: Date.now,
createdAt: date,
carbs: carbs,
fat: fat,
protein: protein,
Expand Down

0 comments on commit f5d301e

Please sign in to comment.