]> git.ktnx.net Git - mobile-ledger.git/commitdiff
omit use of deprecated Date.getYear() and Date.getMonth()
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 14 Mar 2020 16:40:40 +0000 (18:40 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 14 Mar 2020 16:40:40 +0000 (18:40 +0200)
app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/utils/Globals.java

index 5093d50c952287846284c1390e07da2259453b23..815f37fe5f1ab46046ab93c07e13e51164dc648d 100644 (file)
@@ -65,20 +65,22 @@ public class UpdateTransactionsTask extends AsyncTask<String, Void, String> {
             debug("UTT", sql);
             SQLiteDatabase db = App.getDatabase();
             String lastDateString = Globals.formatLedgerDate(new Date());
-            Date lastDate = Globals.parseLedgerDate(lastDateString);
+            Calendar lastDate = Globals.parseLedgerDateAsCalendar(lastDateString);
             boolean odd = true;
             try (Cursor cursor = db.rawQuery(sql, params)) {
                 while (cursor.moveToNext()) {
-                    if (isCancelled()) return null;
+                    if (isCancelled())
+                        return null;
 
                     int transaction_id = cursor.getInt(0);
                     String dateString = cursor.getString(1);
-                    Date date = Globals.parseLedgerDate(dateString);
+                    Calendar date = Globals.parseLedgerDateAsCalendar(dateString);
 
                     if (!lastDateString.equals(dateString)) {
-                        boolean showMonth = (date.getMonth() != lastDate.getMonth() ||
-                                             date.getYear() != lastDate.getYear());
-                        newList.add(new TransactionListItem(date, showMonth));
+                        boolean showMonth =
+                                (date.get(Calendar.MONTH) != lastDate.get(Calendar.MONTH)) ||
+                                (date.get(Calendar.YEAR) != lastDate.get(Calendar.YEAR));
+                        newList.add(new TransactionListItem(date.getTime(), showMonth));
                     }
                     newList.add(
                             new TransactionListItem(new LedgerTransaction(transaction_id), odd));
index 56a88ceca9fa70ef8d4f4de91f76c0a16df869eb..fe0cbe08e3d968127c730cd2620e436669ee51e5 100644 (file)
@@ -82,6 +82,12 @@ public final class Globals {
 
         return dateFormatter.get().parse(toParse);
     }
+    public static Calendar parseLedgerDateAsCalendar(String dateString) throws ParseException {
+        Date date = parseLedgerDate(dateString);
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar;
+    }
     public static Date parseIsoDate(String dateString) throws ParseException {
         return isoDateFormatter.get().parse(dateString);
     }