Browse Source

Check if this is a backdated entry by comparing with the default date using a tolerance

Marvin Polscheit 11 months ago
parent
commit
ff4d60b48b

+ 2 - 2
Trio/Sources/Modules/Treatments/TreatmentsStateModel.swift

@@ -391,8 +391,8 @@ extension Treatments {
                 simulatedCOB = min(maxCobInt16, cobInt16)
             }
 
-            // Check if this is a backdated entry by comparing with the default date
-            let isBackdated = date != defaultDate
+            // Check if this is a backdated entry by comparing with the default date using a tolerance
+            let isBackdated = abs(date.timeIntervalSince(defaultDate)) > 1.0
 
             let result = await bolusCalculationManager.handleBolusCalculation(
                 carbs: carbs,

+ 3 - 3
Trio/Sources/Modules/Treatments/View/ForecastChart.swift

@@ -50,9 +50,9 @@ struct ForecastChart: View {
     }
 
     private var forecastChartLabels: some View {
-        // Check if this is a backdated entry by comparing with the default date
-        let isBackdated = state.date != state.defaultDate
-        
+        // Check if this is a backdated entry by comparing with the default date using a tolerance
+        let isBackdated = abs(state.date.timeIntervalSince(state.defaultDate)) > 1.0
+
         // When backdated, display no carbs as this label is only supposed to show current entered carbs
         let displayedCarbs = isBackdated ? 0 : state.carbs
 

+ 2 - 2
Trio/Sources/Modules/Treatments/View/PopupView.swift

@@ -312,8 +312,8 @@ struct PopupView: View {
     /// Don't allow total carbs to exceed Max IOB setting.
     /// Formula: (Current COB + New Carbs) / Carb Ratio = COB Correction Dose
     private var cobCardContent: some View {
-        // Check if this is a backdated entry by comparing with the default date
-        let isBackdated = state.date != state.defaultDate
+        // Check if this is a backdated entry by comparing with the default date using a tolerance
+        let isBackdated = abs(state.date.timeIntervalSince(state.defaultDate)) > 1.0
 
         // Determine COB and carbs to display based on backdating status
         let displayedCOB = isBackdated ? (state.simulatedDetermination?.cob ?? Decimal(state.cob)) : Decimal(state.cob)