+ private static final ThreadLocal<SimpleDateFormat> dateFormatter =
+ new ThreadLocal<SimpleDateFormat>() {
+ @Override
+ protected SimpleDateFormat initialValue() {
+ 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 final String developerEmail = "dam+mole-crash@ktnx.net";
+ private static final Pattern reLedgerDate =
+ Pattern.compile("^(?:(?:(\\d+)/)??(\\d\\d?)/)?(\\d\\d?)$");
+ public static void hideSoftKeyboard(Activity act) {
+ // hide the keyboard
+ View v = act.getCurrentFocus();
+ if (v != null) {
+ InputMethodManager imm =
+ (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
+ }
+ }
+ public static SimpleDate parseLedgerDate(String dateString) throws ParseException {
+ Matcher m = reLedgerDate.matcher(dateString);
+ if (!m.matches()) throw new ParseException(
+ String.format("'%s' does not match expected pattern '%s'", dateString,
+ reLedgerDate.toString()), 0);
+
+ String yearStr = m.group(1);
+ String monthStr = m.group(2);
+ String dayStr = m.group(3);
+
+ int year, month, day;
+
+ String toParse;
+ if (yearStr == null) {
+ SimpleDate today = SimpleDate.today();
+ year = today.year;
+ if (monthStr == null) {
+ month = today.month;
+ }
+ else month = Integer.parseInt(monthStr);
+ }
+ else {
+ year = Integer.parseInt(yearStr);
+ assert monthStr != null;
+ month = Integer.parseInt(monthStr);
+ }
+
+ assert dayStr != null;
+ day = Integer.parseInt(dayStr);