Skip to content

Commit 1d0d73a

Browse files
authored
Merge pull request #449 from loopandlearn/missed-reading-alert
Fix(alarm): Correct logic for missed reading alert
2 parents e2e8b20 + ecd912f commit 1d0d73a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

LoopFollow/Alarm/AlarmCondition/MissedReadingCondition.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct MissedReadingCondition: AlarmCondition {
99
static let type: AlarmType = .missedReading
1010
init() {}
1111

12-
func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
12+
func evaluate(alarm: Alarm, data: AlarmData, now : Date) -> Bool {
1313
// ────────────────────────────────
1414
// 0. sanity checks
1515
// ────────────────────────────────
@@ -18,7 +18,7 @@ struct MissedReadingCondition: AlarmCondition {
1818
// Skip if we have *no* readings
1919
guard let last = data.bgReadings.last else { return false }
2020

21-
let secondsSinceLast = Date().timeIntervalSince(last.date)
21+
let secondsSinceLast = now.timeIntervalSince(last.date)
2222
return secondsSinceLast >= thresholdMinutes * 60
2323
}
2424
}

LoopFollow/Alarm/AlarmManager.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ class AlarmManager {
7070
continue
7171
}
7272

73-
// If the alarm is based on bg values, and the value isnt recent, skip to next
74-
if alarm.type.isBGBased, !isLatestReadingRecent {
73+
// If an alarm is BG-based, it usually requires recent data.
74+
// We make a specific exception for .missedReading, whose entire
75+
// purpose is to fire when recent BG data is NOT recent.
76+
if alarm.type.isBGBased, alarm.type != .missedReading, !isLatestReadingRecent {
7577
continue
7678
}
7779

0 commit comments

Comments
 (0)