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; /** * Created by camilstaps on 7-4-15. */ 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; } public String getText() { return text; } public Date getDate() { return date; } @Override public String toString() { JSONObject json = new JSONObject(); try { json.put("date", dateFormatter.format(date)); json.put("text", text); } catch (JSONException e) {} return json.toString(); } 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")); } }