1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 10:56:50 +01:00

Fix getLocalDate month off-by-1

This commit is contained in:
José Rebelo 2024-08-31 21:33:24 +01:00
parent e676f7c6b0
commit 834c773dec

View File

@ -216,13 +216,8 @@ public class Prefs {
public LocalDate getLocalDate(final String key, final String defaultValue) {
final String time = getString(key, defaultValue);
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
try {
final Date parse = df.parse(time);
final Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(parse);
return LocalDate.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
return LocalDate.parse(time);
} catch (final Exception e) {
Log.e(TAG, "Error reading localdate preference value: " + key + "; returning default current day", e); // log the first exception
}
@ -230,7 +225,6 @@ public class Prefs {
return LocalDate.now();
}
private void logReadError(String key, Exception ex) {
Log.e(TAG, "Error reading preference value: " + key + "; returning default value", ex); // log the first exception
}