From c19787694e7d5db1f691fcfeffab796689c0e002 Mon Sep 17 00:00:00 2001 From: jacques Date: Thu, 1 Apr 2021 21:28:30 +0200 Subject: [PATCH] Fix a bug in scheduleAlarm with the timeZone. --- .../foucry/pilldroid/MedicamentListActivity.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java index a6f99c0..c13e83e 100644 --- a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -32,16 +32,14 @@ import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; import java.text.SimpleDateFormat; +import java.time.LocalTime; import java.util.Date; import java.util.List; import java.util.Locale; import static net.foucry.pilldroid.UtilDate.date2String; -import static net.foucry.pilldroid.UtilDate.dateAtNoon; import static net.foucry.pilldroid.Utils.intRandomExclusive; -// Todo: - use same color in website and about - /** * An activity representing a list of Medicaments. This activity * has different presentations for handset and tablet-size devices. On @@ -369,21 +367,22 @@ public class MedicamentListActivity extends AppCompatActivity { public void scheduleAlarm() { Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY,12); Date today = calendar.getTime(); calendar.add(Calendar.DAY_OF_YEAR, 1); - Date tomorow = calendar.getTime(); + Date tomorrow = calendar.getTime(); - if (today.before(dateAtNoon(today))) { + LocalTime todayNow = LocalTime.now(); + + if (todayNow.isBefore(LocalTime.NOON)) { // schedule date = today //calendar.setTimeInMillis(dateAtNoon(today).getTime()); calendar.setTimeInMillis(today.getTime()); } else { // schedule date = tomorrow - calendar.setTimeInMillis(tomorow.getTime()); + calendar.setTimeInMillis(tomorrow.getTime()); } - calendar.set(Calendar.HOUR_OF_DAY,12); - PendingIntent alarmIntent; Intent intent = new Intent(this, AlarmReceiver.class);