From adc322be37a07ad04bede07ba0a198faed0895b0 Mon Sep 17 00:00:00 2001 From: Reimar Date: Thu, 9 Dec 2021 08:11:19 +0100 Subject: [PATCH] fix wrong minuteChange for values < 40 --- LibreDirect/Content/SensorReading.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/LibreDirect/Content/SensorReading.swift b/LibreDirect/Content/SensorReading.swift index 1337d7a2d..0e0236062 100644 --- a/LibreDirect/Content/SensorReading.swift +++ b/LibreDirect/Content/SensorReading.swift @@ -11,14 +11,27 @@ final class SensorReading: CustomStringConvertible, Codable { init(id: UUID, timestamp: Date, glucoseValue: Double) { self.id = id self.timestamp = timestamp.rounded(on: 1, .minute) - self.glucoseValue = glucoseValue + self.readGlucoseValue = glucoseValue } // MARK: Internal let id: UUID let timestamp: Date - let glucoseValue: Double + let readGlucoseValue: Double + + var glucoseValue: Double { + let minReadableGlucose = Double(AppConfig.MinReadableGlucose) + let maxReadableGlucose = Double(AppConfig.MaxReadableGlucose) + + if readGlucoseValue < minReadableGlucose { + return minReadableGlucose + } else if readGlucoseValue > maxReadableGlucose { + return maxReadableGlucose + } + + return readGlucoseValue + } var description: String { [