aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/camilstaps/taize/DailyReading.java
blob: 71acc2ba6bcf278fab5016721a9708b671631dc7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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"));
    }
}