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

Merge pull request #619 from marv-out/carbBackdating

Replace logic for check for backdated carbs
Deniz Cengiz 11 месяцев назад
Родитель
Сommit
a2fa4cbfdd

+ 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,

+ 2 - 4
Trio/Sources/Modules/Treatments/View/ForecastChart.swift

@@ -50,10 +50,8 @@ struct ForecastChart: View {
     }
 
     private var forecastChartLabels: some View {
-        // 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 = state.date.timeIntervalSinceNow < -minutesThreshold * 60 && state.simulatedDetermination != nil
+        // 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 - 4
Trio/Sources/Modules/Treatments/View/PopupView.swift

@@ -312,10 +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 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 = state.date.timeIntervalSinceNow < -minutesThreshold * 60 && state.simulatedDetermination != nil
+        // 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)