From 5088d912de53ecb3852aec984b9fc82bb95127c4 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 9 Jan 2021 11:17:10 +0100 Subject: [PATCH] Improve new stock calcultation --- app/src/main/java/net/foucry/pilldroid/Medicament.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/Medicament.java b/app/src/main/java/net/foucry/pilldroid/Medicament.java index 102e09a..93749a2 100644 --- a/app/src/main/java/net/foucry/pilldroid/Medicament.java +++ b/app/src/main/java/net/foucry/pilldroid/Medicament.java @@ -163,8 +163,10 @@ public class Medicament implements Serializable { void newStock() { Date lastUpdate = new Date(getDateLastUpdate()); int numberOfDays = nbOfDaysBetweenDateAndToday(lastUpdate); - double takeDuringPeriod = this.prise * numberOfDays; - setStock(getStock() - takeDuringPeriod); - setDateLastUpdate(dateAtNoon(new Date()).getTime()); + if (numberOfDays > 0) { + double takeDuringPeriod = this.prise * numberOfDays; + setStock(getStock() - takeDuringPeriod); + setDateLastUpdate(new Date().getTime()); + } } } \ No newline at end of file