- Small fix in case that saved date is invalid (shouldn't be)

This commit is contained in:
Andy Rozman 2019-06-29 21:02:51 +01:00
parent 9a1377fd78
commit f544f19a02
3 changed files with 34 additions and 12 deletions

View file

@ -1,4 +1,3 @@
package info.nightscout.androidaps.plugins.general.overview.notifications;
import java.util.Date;
@ -86,6 +85,7 @@ public class Notification {
public NSAlarm nsAlarm = null;
public Integer soundId = null;
public Notification() {
}

View file

@ -49,7 +49,7 @@ public class DateTimeUtil {
return new LocalDateTime(year, month, dayOfMonth, hourOfDay, minute, second);
} catch (Exception ex) {
if (L.isEnabled(L.PUMPCOMM))
LOG.error("Error creating LocalDateTime from values [atechDateTime=%d, year=%d, month=%d, day=%d, hour=%d, minute=%d, second=%d]", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second);
LOG.error("Error creating LocalDateTime from values [atechDateTime={}, year={}, month={}, day={}, hour={}, minute={}, second={}]. Exception: {}", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second, ex.getMessage());
//return null;
throw ex;
}

View file

@ -14,7 +14,9 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -1102,7 +1104,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (isLoggingEnabled())
LOG.debug(getLogPrefix() + "readPumpHistoryLogic(): lastPumpHistoryEntry: null");
Long lastPumpHistoryEntryTime = SP.getLong(MedtronicConst.Statistics.LastPumpHistoryEntry, 0L);
Long lastPumpHistoryEntryTime = getLastPumpEntryTime();
LocalDateTime timeMinus36h = new LocalDateTime();
timeMinus36h = timeMinus36h.minusHours(36);
@ -1197,6 +1199,26 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
private Long getLastPumpEntryTime() {
Long lastPumpEntryTime = SP.getLong(MedtronicConst.Statistics.LastPumpHistoryEntry, 0L);
try {
LocalDateTime localDateTime = DateTimeUtil.toLocalDateTime(lastPumpEntryTime);
if (localDateTime.getYear() != (new GregorianCalendar().get(Calendar.YEAR))) {
LOG.warn("Saved LastPumpHistoryEntry was invalid. Year was not the same.");
return 0L;
}
return lastPumpEntryTime;
} catch (Exception ex) {
LOG.warn("Saved LastPumpHistoryEntry was invalid.");
return 0L;
}
}
private void scheduleNextRefresh(MedtronicStatusRefreshType refreshType) {
scheduleNextRefresh(refreshType, 0);