Fix a bug in scheduleAlarm with the timeZone.

This commit is contained in:
jacques 2021-04-01 21:28:30 +02:00
parent 43b4010b22
commit c19787694e

View file

@ -32,16 +32,14 @@ import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult; import com.google.zxing.integration.android.IntentResult;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import static net.foucry.pilldroid.UtilDate.date2String; import static net.foucry.pilldroid.UtilDate.date2String;
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
import static net.foucry.pilldroid.Utils.intRandomExclusive; import static net.foucry.pilldroid.Utils.intRandomExclusive;
// Todo: - use same color in website and about
/** /**
* An activity representing a list of Medicaments. This activity * An activity representing a list of Medicaments. This activity
* has different presentations for handset and tablet-size devices. On * has different presentations for handset and tablet-size devices. On
@ -369,21 +367,22 @@ public class MedicamentListActivity extends AppCompatActivity {
public void scheduleAlarm() { public void scheduleAlarm() {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,12);
Date today = calendar.getTime(); Date today = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, 1); 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 // schedule date = today
//calendar.setTimeInMillis(dateAtNoon(today).getTime()); //calendar.setTimeInMillis(dateAtNoon(today).getTime());
calendar.setTimeInMillis(today.getTime()); calendar.setTimeInMillis(today.getTime());
} else { } else {
// schedule date = tomorrow // schedule date = tomorrow
calendar.setTimeInMillis(tomorow.getTime()); calendar.setTimeInMillis(tomorrow.getTime());
} }
calendar.set(Calendar.HOUR_OF_DAY,12);
PendingIntent alarmIntent; PendingIntent alarmIntent;
Intent intent = new Intent(this, AlarmReceiver.class); Intent intent = new Intent(this, AlarmReceiver.class);