Просмотр исходного кода

Fix condition for passing through simulatedCOB to match popup logic

Marvin Polscheit 1 год назад
Родитель
Сommit
d6e050ac11
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      Trio/Sources/Modules/Treatments/TreatmentsStateModel.swift

+ 6 - 1
Trio/Sources/Modules/Treatments/TreatmentsStateModel.swift

@@ -380,8 +380,13 @@ extension Treatments {
                 minPredBG
             }
 
+            // Check if carbs are actually backdated (more than 15 minutes in the past)
+            // This ensures we only consider it backdated if the user has deliberately changed the date
+            let minutesThreshold = 15.0 // 15 minutes threshold
+            let isBackdated = date.timeIntervalSinceNow < -minutesThreshold * 60 && simulatedDetermination != nil
+
             // Use the cob value of the simulation if carbs are backdated, otherwise set `simulatedCOB` to nil so that the cob value of the most recent determination gets used in the Bolus Calc Manager
-            let simulatedCOB: Int16? = (simulatedDetermination != nil && date < Date()) ?
+            let simulatedCOB: Int16? = isBackdated ?
                 Int16(truncating: NSNumber(value: (simulatedDetermination?.cob as NSDecimalNumber?)?.doubleValue ?? 0)) : nil
 
             let result = await bolusCalculationManager.handleBolusCalculation(