Example #1
0
  private JSONObject castEventToJSONObj(Event event) {
    JSONObject jsonObj = new JSONObject();

    DateFormat dfDeadline = new SimpleDateFormat("yyyy-M-dd");
    Date deadLine = null;

    try {
      deadLine = dfDeadline.parse("1970-01-01");
    } catch (ParseException e) {
      e.printStackTrace();
    }

    try {
      jsonObj.put("name", event.getName());
      jsonObj.put("description", event.getDescription());
      jsonObj.put("category", event.getCategory());
      jsonObj.put("status", event.getStatus());
      jsonObj.put("location", event.getLocation());

      if (event.getCategory().equals(GenericEvent.Category.DEADLINE)) {
        jsonObj.put("startTime", deadLine);
        jsonObj.put("endTime", event.getEndTime());
      } else {
        jsonObj.put("startTime", event.getStartTime());
        jsonObj.put("endTime", event.getEndTime());
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }

    return jsonObj;
  }
Example #2
0
  private Event castJSONObjToEvent(JSONObject jsonObj) {
    Event event = new Event();
    DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", Locale.ENGLISH);

    try {
      String startTime = jsonObj.get("startTime").toString();
      String endTime = jsonObj.get("endTime").toString();

      event.setName(jsonObj.getString("name"));
      event.setDescription(jsonObj.getString("description"));
      event.setCategory(getCategory(jsonObj));
      event.setStatus(getStatus(jsonObj));
      event.setLocation(jsonObj.getString("location"));

      if (event.getCategory().equals(GenericEvent.Category.FLOATING)) {
        // doesn't set start time and end time
      } else {
        event.setStartTime(df.parse(startTime));
        event.setEndTime(df.parse(endTime));
      }

    } catch (JSONException e2) {
      e2.printStackTrace();
    } catch (ParseException e1) {
      e1.printStackTrace();
    }

    return event;
  }