From 7dfa7071e309e006e264edfdf0067bdcbe76227f Mon Sep 17 00:00:00 2001 From: Alexander Ivanov Date: Sat, 22 Oct 2022 18:54:37 +0300 Subject: [PATCH] Fix DatePickerDialog sometimes storing dates at 12:00 PM instead of 12:00 AM --- .../java/protect/card_locker/LoyaltyCardEditActivity.java | 5 +++-- app/src/main/java/protect/card_locker/Utils.java | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java index 3f3eb39d0..d909808fd 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardEditActivity.java @@ -59,6 +59,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Currency; import java.util.Date; +import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -1275,11 +1276,11 @@ public class LoyaltyCardEditActivity extends CatimaAppCompatActivity { } public void onDateSet(DatePicker view, int year, int month, int day) { - Calendar c = Calendar.getInstance(); + Calendar c = new GregorianCalendar(); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month); c.set(Calendar.DAY_OF_MONTH, day); - c.set(Calendar.HOUR, 0); + c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index 86b4b5870..9c7a9a770 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -217,6 +217,11 @@ public class Utils { date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); + // Note: In #1083 it was discovered that `DatePickerFragment` may sometimes store the expiryDate + // at 12:00 PM instead of 12:00 AM in the DB. While this has been fixed and the 12-hour difference + // is not a problem for the way the comparison currently works, it's good to keep in mind such + // dates may exist in the DB in case the comparison changes in the future and the new one relies + // on both dates being set at 12:00 AM. return expiryDate.before(date.getTime()); }