Correctly infer pump date when crossing midnight. Fixes #35.

(cherry picked from commit bda2551)
This commit is contained in:
Johannes Mockenhaupt 2017-12-31 00:18:10 +01:00
parent 220554dbd6
commit a6b938d98a
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 11 additions and 3 deletions

View file

@ -804,9 +804,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (state.pumpTime == 0) {
// time couldn't be read (e.g. a warning is displayed on the menu , hiding the time field)
} else if (Math.abs(state.pumpTime - System.currentTimeMillis()) >= 10 * 60 * 1000) {
log.debug("Pump clock needs update, pump time: " + state.pumpTime + " (" + new Date(state.pumpTime) + ")");
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_notification_check_time_date), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else if (Math.abs(state.pumpTime - System.currentTimeMillis()) >= 3 * 60 * 1000) {
log.debug("Pump clock needs update, pump time: " + state.pumpTime + " (" + new Date(state.pumpTime) + ")");
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.sResources.getString(R.string.combo_notification_check_time_date), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification));
}

View file

@ -520,10 +520,16 @@ public class RuffyScripter implements RuffyCommands {
state.insulinState = ((int) menu.getAttribute(MenuAttribute.INSULIN_STATE));
}
if (menu.attributes().contains(MenuAttribute.TIME)) {
MenuTime time = (MenuTime) menu.getAttribute(MenuAttribute.TIME);
MenuTime pumpTime = (MenuTime) menu.getAttribute(MenuAttribute.TIME);
Date date = new Date();
date.setHours(time.getHour());
date.setMinutes(time.getMinute());
// infer yesterday as the pump's date if midnight just passed, but the pump is
// a bit behind
if (date.getHours() == 0 && date.getMinutes() <= 5
&& pumpTime.getHour() == 23 && pumpTime.getMinute() >= 55) {
date.setTime(date.getTime() - 24 * 60 * 60 * 1000);
}
date.setHours(pumpTime.getHour());
date.setMinutes(pumpTime.getMinute());
date.setSeconds(0);
state.pumpTime = date.getTime() - date.getTime() % 1000;
}