X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Futils%2FGlobals.java;h=8a2c8366659e76253082e0915626a48c02b539bd;hb=c2b76737c32b75f5e4bd45f1e7b466f948101ca3;hp=30dec945a994b076385157d3ad22c8d3efc6a28d;hpb=e12bae55fb75c0c30055dd34ded195e75feb3844;p=mobile-ledger.git
diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Globals.java b/app/src/main/java/net/ktnx/mobileledger/utils/Globals.java
index 30dec945..8a2c8366 100644
--- a/app/src/main/java/net/ktnx/mobileledger/utils/Globals.java
+++ b/app/src/main/java/net/ktnx/mobileledger/utils/Globals.java
@@ -1,18 +1,18 @@
/*
* Copyright © 2019 Damyan Ivanov.
- * This file is part of Mobile-Ledger.
- * Mobile-Ledger is free software: you can distribute it and/or modify it
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
* under the term of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your opinion), any later version.
*
- * Mobile-Ledger is distributed in the hope that it will be useful,
+ * MoLe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License terms for details.
*
* You should have received a copy of the GNU General Public License
- * along with Mobile-Ledger. If not, see .
+ * along with MoLe. If not, see .
*/
package net.ktnx.mobileledger.utils;
@@ -25,17 +25,25 @@ import android.view.inputmethod.InputMethodManager;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public final class Globals {
@ColorInt
- public static int tableRowEvenBG;
+ public static int tableRowLightBG;
@ColorInt
- public static int tableRowOddBG;
+ public static int tableRowDarkBG;
@ColorInt
public static int primaryDark, defaultTextColor;
public static String[] monthNames;
+ public static String developerEmail = "dam+mole-crash@ktnx.net";
+ private static SimpleDateFormat ledgerDateFormatter =
+ new SimpleDateFormat("yyyy/MM/dd", Locale.US);
+ private static Pattern reLedgerDate =
+ Pattern.compile("^(?:(\\d+)/)??(?:(\\d\\d?)/)?(\\d\\d?)$");
public static void hideSoftKeyboard(Activity act) {
// hide the keyboard
View v = act.getCurrentFocus();
@@ -45,14 +53,28 @@ public final class Globals {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
- private static SimpleDateFormat ledgerDateFormatter = new SimpleDateFormat("y/M/d", Locale.US);
- public static Date parseLedgerDate(String dateString) {
- try {
- return ledgerDateFormatter.parse(dateString);
- }
- catch (ParseException e) {
- throw new RuntimeException(String.format("Error parsing date '%s'", dateString), e);
+ public static Date parseLedgerDate(String dateString) throws ParseException {
+ Matcher m = reLedgerDate.matcher(dateString);
+ if (!m.matches()) throw new ParseException(dateString, 0);
+
+ String year = m.group(1);
+ String month = m.group(2);
+ String day = m.group(3);
+
+ String toParse;
+ if (year == null) {
+ Calendar now = Calendar.getInstance();
+ int thisYear = now.get(Calendar.YEAR);
+ if (month == null) {
+ int thisMonth = now.get(Calendar.MONTH) + 1;
+ toParse = String.format(Locale.US, "%04d/%02d/%s", thisYear, thisMonth, dateString);
+ }
+ else toParse = String.format(Locale.US, "%04d/%s", thisYear, dateString);
}
+ else toParse = dateString;
+
+// Log.d("globals", String.format("Parsing date '%s'", toParse));
+ return ledgerDateFormatter.parse(toParse);
}
public static String formatLedgerDate(Date date) {
return ledgerDateFormatter.format(date);