aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/camilstaps/taize/DailyReading.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/camilstaps/taize/DailyReading.java')
-rw-r--r--app/src/main/java/com/camilstaps/taize/DailyReading.java38
1 files changed, 31 insertions, 7 deletions
diff --git a/app/src/main/java/com/camilstaps/taize/DailyReading.java b/app/src/main/java/com/camilstaps/taize/DailyReading.java
index 71acc2b..71c38ac 100644
--- a/app/src/main/java/com/camilstaps/taize/DailyReading.java
+++ b/app/src/main/java/com/camilstaps/taize/DailyReading.java
@@ -3,10 +3,11 @@ package com.camilstaps.taize;
import org.json.JSONException;
import org.json.JSONObject;
-import java.io.Serializable;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.camilstaps.common.Date;
/**
* Created by camilstaps on 7-4-15.
@@ -16,8 +17,6 @@ public class DailyReading {
private final Date date;
private final String text;
- private static SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
-
public DailyReading(Date date, String text) {
this.date = date;
this.text = text;
@@ -31,11 +30,21 @@ public class DailyReading {
return date;
}
+ public String getTextWithoutReference() {
+ Matcher bible_ref_m = referenceMatcher();
+
+ if (bible_ref_m.find()) {
+ return text.substring(0, bible_ref_m.start() - 1);
+ } else {
+ return text;
+ }
+ }
+
@Override
public String toString() {
JSONObject json = new JSONObject();
try {
- json.put("date", dateFormatter.format(date));
+ json.put("date", date.toString());
json.put("text", text);
} catch (JSONException e) {}
return json.toString();
@@ -43,6 +52,21 @@ public class DailyReading {
public static DailyReading fromString(String s) throws JSONException, ParseException {
JSONObject json = new JSONObject(s);
- return new DailyReading(dateFormatter.parse(json.getString("date")), json.getString("text"));
+ return new DailyReading(new Date(json.getString("date")), json.getString("text"));
+ }
+
+ public BibleText getBibleReference() {
+ final Matcher bible_ref_m = referenceMatcher();
+
+ if (!bible_ref_m.find()) {
+ return null;
+ }
+
+ return new BibleText(bible_ref_m.group(1), Integer.parseInt(bible_ref_m.group(2)), Integer.parseInt(bible_ref_m.group(3)), Integer.parseInt(bible_ref_m.group(2)), Integer.parseInt(bible_ref_m.group(4)));
+ }
+
+ private Matcher referenceMatcher() {
+ Pattern bible_ref = Pattern.compile("\\((\\d? ?[a-zA-Z]+) (\\d{1,2})(?::|,)(\\d+)-?(\\d+?)\\)");
+ return bible_ref.matcher(text);
}
}