Merge pull request #1103 from vanogrid/fix/storingDateAt12pm

Fix DatePickerDialog sometimes storing dates at 12 PM instead of 12 AM
This commit is contained in:
Sylvia van Os
2022-10-23 11:55:25 +02:00
committed by GitHub
2 changed files with 8 additions and 2 deletions

View File

@@ -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);

View File

@@ -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());
}