Skip to content

Commit f9cc1ec

Browse files
authored
Merge pull request #6 from LoopKit/time-crash
Prevent negative duration doses
2 parents 4fc4613 + 7aaf762 commit f9cc1ec

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

MinimedKit/PumpManager/UnfinalizedDose.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ public struct UnfinalizedDose: RawRepresentable, Equatable, CustomStringConverti
117117

118118
let programmedUnits = units
119119
self.programmedUnits = programmedUnits
120-
let newDuration = date.timeIntervalSince(startTime)
120+
121+
// Guard against negative duration if clock has changed
122+
let newDuration = max(0, date.timeIntervalSince(startTime))
121123

122124
switch doseType {
123125
case .bolus:

0 commit comments

Comments
 (0)