Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove actual date #60

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(), actualDate: useDate,
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: 0 additions & 2 deletions FreeAPS/Sources/Models/CarbsEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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 @@ -28,7 +27,6 @@ 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: 1 addition & 2 deletions FreeAPS/Sources/Modules/AddCarbs/AddCarbsStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ extension AddCarbs {
carbsStorage.storeCarbs(
[CarbsEntry(
id: UUID().uuidString,
createdAt: Date.now,
actualDate: date,
createdAt: date,
carbs: carbs,
fat: fat,
protein: protein,
Expand Down
6 changes: 3 additions & 3 deletions FreeAPS/Sources/Services/HealthKit/HealthKitManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ final class BaseHealthKitManager: HealthKitManager, Injectable, CarbsObserver, P
let sampleDates = samples.map(\.startDate)
let samplesToSave = carbsWithId
.filter { !sampleIDs.contains($0.id ?? "") } // id existing in AH
.filter { !sampleDates.contains($0.actualDate ?? $0.createdAt) } // not id but exactly the same datetime
.filter { !sampleDates.contains($0.createdAt) } // not id but exactly the same datetime
.map {
HKQuantitySample(
type: sampleType,
quantity: HKQuantity(unit: .gram(), doubleValue: Double($0.carbs)),
start: $0.actualDate ?? $0.createdAt,
end: $0.actualDate ?? $0.createdAt,
start: $0.createdAt,
end: $0.createdAt,
metadata: [
HKMetadataKeySyncIdentifier: $0.id ?? "_id",
HKMetadataKeySyncVersion: 1,
Expand Down
1 change: 0 additions & 1 deletion FreeAPS/Sources/Services/WatchManager/WatchManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ extension BaseWatchManager: WCSessionDelegate {
[CarbsEntry(
id: UUID().uuidString,
createdAt: Date.now,
actualDate: Date.now,
carbs: Decimal(carbs),
fat: Decimal(fat),
protein: Decimal(protein), note: nil,
Expand Down