parser method for ISO date format (yyyy-mm-dd)
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 7 Mar 2019 03:37:12 +0000 (05:37 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 7 Mar 2019 03:37:12 +0000 (05:37 +0200)
app/src/main/java/net/ktnx/mobileledger/utils/Globals.java

index 8f010cb..719d6e2 100644 (file)
@@ -38,6 +38,13 @@ public final class Globals {
                     return new SimpleDateFormat("yyyy/MM/dd", Locale.US);
                 }
             };
+    private static final ThreadLocal<SimpleDateFormat> isoDateFormatter =
+            new ThreadLocal<SimpleDateFormat>() {
+                @Override
+                protected SimpleDateFormat initialValue() {
+                    return new SimpleDateFormat("yyyy-MM-dd", Locale.US);
+                }
+            };
     public static String[] monthNames;
     public static String developerEmail = "dam+mole-crash@ktnx.net";
     private static Pattern reLedgerDate =
@@ -75,6 +82,9 @@ public final class Globals {
 
         return dateFormatter.get().parse(toParse);
     }
+    public static Date parseIsoDate(String dateString) throws ParseException {
+        return isoDateFormatter.get().parse(dateString);
+    }
     public static String formatLedgerDate(Date date) {
         return dateFormatter.get().format(date);
     }