Skip to content

Commit 3d1f6a8

Browse files
authored
Merge pull request loopandlearn#391 from loopandlearn/enacted-timestamp-check
Ignore old enacted timestamps
2 parents ce4f36f + a527dbc commit 3d1f6a8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ extension MainViewController {
2525
wasEnacted = true
2626
if let timestampString = enacted["timestamp"] as? String,
2727
let lastLoopTime = formatter.date(from: timestampString)?.timeIntervalSince1970 {
28-
UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
29-
LogManager.shared.log(category: .deviceStatus, message: "New LastLoopTime: \(lastLoopTime)", isDebug: true)
28+
let storedTime = UserDefaultsRepository.alertLastLoopTime.value
29+
if lastLoopTime < storedTime {
30+
LogManager.shared.log(category: .deviceStatus, message: "Received an old timestamp for enacted: \(lastLoopTime) is older than last stored time \(storedTime), ignoring update.", isDebug: false)
31+
} else {
32+
UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
33+
LogManager.shared.log(category: .deviceStatus, message: "New LastLoopTime: \(lastLoopTime)", isDebug: true)
34+
}
3035
}
3136
} else {
3237
wasEnacted = false

0 commit comments

Comments
 (0)