Make TreatmentsPlugin.getLastBolusTime robust.

Ignore carb-only treatments, ignore future records.

(cherry picked from commit cba015e)
This commit is contained in:
Johannes Mockenhaupt 2018-01-29 02:50:21 +01:00
parent b4d13c727e
commit b1fd66aae5
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -288,12 +288,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Override @Override
public long getLastBolusTime() { public long getLastBolusTime() {
long now = System.currentTimeMillis();
long last = 0; long last = 0;
for (Integer pos = 0; pos < treatments.size(); pos++) { for (Treatment t : treatments) {
Treatment t = treatments.get(pos); if (t.date > last && t.insulin > 0 && t.isValid && t.date <= now)
if (!t.isValid)
continue;
if (t.date > last)
last = t.date; last = t.date;
} }
log.debug("Last bolus time: " + new Date(last).toLocaleString()); log.debug("Last bolus time: " + new Date(last).toLocaleString());