From 834c773dec88a68626e723da210bc2dc5fe87ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sat, 31 Aug 2024 21:33:24 +0100 Subject: [PATCH] Fix getLocalDate month off-by-1 --- .../nodomain/freeyourgadget/gadgetbridge/util/Prefs.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Prefs.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Prefs.java index c054600a5..c1344d053 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Prefs.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/Prefs.java @@ -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 }