From b1fd66aae55a81774206977a2ed3c1e83f9a6eda Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 29 Jan 2018 02:50:21 +0100 Subject: [PATCH] Make TreatmentsPlugin.getLastBolusTime robust. Ignore carb-only treatments, ignore future records. (cherry picked from commit cba015e) --- .../androidaps/plugins/Treatments/TreatmentsPlugin.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index a9cc37d32b..f0b63b0b6d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -288,12 +288,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { @Override public long getLastBolusTime() { + long now = System.currentTimeMillis(); long last = 0; - for (Integer pos = 0; pos < treatments.size(); pos++) { - Treatment t = treatments.get(pos); - if (!t.isValid) - continue; - if (t.date > last) + for (Treatment t : treatments) { + if (t.date > last && t.insulin > 0 && t.isValid && t.date <= now) last = t.date; } log.debug("Last bolus time: " + new Date(last).toLocaleString());