polscm32 aka Marvout пре 1 година
родитељ
комит
c5884c7fa4

+ 9 - 2
FreeAPS/Sources/Modules/Stat/View/ViewElements/BolusStatsView.swift

@@ -57,8 +57,15 @@ struct BolusStatsView: View {
 
     /// Returns bolus statistics for a specific date
     private func getBolusForDate(_ date: Date) -> BolusStats? {
-        bolusStats.first { stat in
-            Calendar.current.isDate(stat.date, inSameDayAs: date)
+        let calendar = Calendar.current
+
+        return bolusStats.first { stat in
+            switch selectedDuration {
+            case .Day:
+                return calendar.isDate(stat.date, equalTo: date, toGranularity: .hour)
+            default:
+                return calendar.isDate(stat.date, inSameDayAs: date)
+            }
         }
     }
 

+ 9 - 2
FreeAPS/Sources/Modules/Stat/View/ViewElements/MealStatsView.swift

@@ -86,8 +86,15 @@ struct MealStatsView: View {
     /// This function searches through the meal statistics array to find the first entry
     /// that matches the provided date (comparing only the day component, not time).
     private func getMealForDate(_ date: Date) -> MealStats? {
-        mealStats.first { stat in
-            Calendar.current.isDate(stat.date, inSameDayAs: date)
+        let calendar = Calendar.current
+
+        return mealStats.first { stat in
+            switch selectedDuration {
+            case .Day:
+                return calendar.isDate(stat.date, equalTo: date, toGranularity: .hour)
+            default:
+                return calendar.isDate(stat.date, inSameDayAs: date)
+            }
         }
     }
 

+ 9 - 2
FreeAPS/Sources/Modules/Stat/View/ViewElements/TDDChart.swift

@@ -52,8 +52,15 @@ struct TDDChartView: View {
     }
 
     private func getTDDForDate(_ date: Date) -> TDDStats? {
-        tddStats.first { stat in
-            Calendar.current.isDate(stat.date, inSameDayAs: date)
+        let calendar = Calendar.current
+
+        return tddStats.first { stat in
+            switch selectedDuration {
+            case .Day:
+                return calendar.isDate(stat.date, equalTo: date, toGranularity: .hour)
+            default:
+                return calendar.isDate(stat.date, inSameDayAs: date)
+            }
         }
     }