Skip to content

Commit

Permalink
Merge pull request #22 from nightscout/apple-health-fix
Browse files Browse the repository at this point in the history
Backport HealthKit fix to earlier version
  • Loading branch information
AndreasStokholm authored Apr 5, 2024
2 parents 8cd27c3 + 836759f commit 1e8c954
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 136 deletions.
3 changes: 2 additions & 1 deletion FreeAPS/Sources/APS/Storage/CarbsStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
} else { useDate = useDate.addingTimeInterval(interval.minutes.timeInterval) }

let eachCarbEntry = CarbsEntry(
id: UUID().uuidString, createdAt: useDate, carbs: equivalent, fat: 0, protein: 0, note: nil,
id: UUID().uuidString, createdAt: entries.last?.createdAt ?? Date(), actualDate: useDate,
carbs: equivalent, fat: 0, protein: 0, note: nil,
enteredBy: CarbsEntry.manual, isFPU: true,
fpuID: fpuID
)
Expand Down
2 changes: 2 additions & 0 deletions FreeAPS/Sources/Models/CarbsEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
struct CarbsEntry: JSON, Equatable, Hashable {
let id: String?
let createdAt: Date
let actualDate: Date?
let carbs: Decimal
let fat: Decimal?
let protein: Decimal?
Expand All @@ -27,6 +28,7 @@ extension CarbsEntry {
private enum CodingKeys: String, CodingKey {
case id = "_id"
case createdAt = "created_at"
case actualDate
case carbs
case fat
case protein
Expand Down
3 changes: 2 additions & 1 deletion FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ extension AddCarbs {
carbsStorage.storeCarbs(
[CarbsEntry(
id: UUID().uuidString,
createdAt: date,
createdAt: Date.now,
actualDate: date,
carbs: carbs,
fat: fat,
protein: protein,
Expand Down
Loading

0 comments on commit 1e8c954

Please sign in to comment.