public static dix.walton.moore.model.Event convertToOurEvent(Event googleEvent) {

    dix.walton.moore.model.Event internalEvent = new dix.walton.moore.model.Event();

    DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM");
    DateFormat timeFormat = new SimpleDateFormat("HH:mm");
    String startString;
    try {
      startString = googleEvent.getStart().getDateTime().toString();
      int T = startString.indexOf('T');
      internalEvent.setEventDate(startString.substring(0, T));
      internalEvent.setStartTime(startString.substring(T + 1, T + 6));

      if (googleEvent.getEnd() != null) {
        String endString = googleEvent.getEnd().getDateTime().toString();
        T = endString.indexOf('T');
        internalEvent.setEndTime(endString.substring(T + 1, T + 6));
      }
    } catch (Exception e) {
      System.out.println("Exception thrown");
    }

    internalEvent.setId(googleEvent.getId());
    internalEvent.setLocation(googleEvent.getLocation());
    internalEvent.setTitle(googleEvent.getSummary());
    return internalEvent;
  }
  private static GEvent newGEvent(Event event, GCalendar calendar) {
    DateTime start = event.getStart().getDateTime();
    DateTime end = event.getEnd().getDateTime();
    if (start == null) {
      // All-day events don't have start times, so just use
      // the start date.
      start = event.getStart().getDate();
    }
    if (end == null) {
      end = event.getEnd().getDate();
    }
    Calendar startEvent = new GregorianCalendar();
    Calendar endEvent = new GregorianCalendar();
    startEvent.setTime(new Date(start.getValue()));
    endEvent.setTime(new Date(end.getValue()));

    //        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd H:m:s");
    //        Log.d("gevent", "start = " + format1.format(startEvent.getTime()) + ", end = " +
    // format1.format(endEvent.getTime()));

    GEvent nEvent = new GEvent(event.getSummary(), startEvent, endEvent);
    nEvent.SetBackgroundColor(calendar.backgroundColor);
    nEvent.SetForegroundColor(calendar.foregroundColor);

    return nEvent;
  }
  public String getTimeDescription() {
    EventDateTime startDT = event.getStart();
    EventDateTime endDT = event.getEnd();
    // this field is populated if event has time
    if (startDT.getDateTime() != null) {
      return String.format(
          "Start: %s End: %s",
          formatDateTime(startDT.getDateTime()), formatDateTime(endDT.getDateTime()));
    }
    DateTime startDate = startDT.getDate();
    DateTime endDate = endDT.getDate();
    // special case for 1 full day event - just show the one date instead of start end
    final long oneDayTime = 1000 * 60 * 60 * 24;
    if (endDate.getValue() - startDate.getValue() == oneDayTime)
      return String.format("Date: %s", startDate);

    return String.format("Start: %s End: %s", startDate, endDate);
  }
Example #4
0
  public Event(com.google.api.services.calendar.model.Event current, int $colorNumber) {
    name = current.getSummary();
    summary = current.getDescription();
    Calendar calS = Calendar.getInstance();
    Calendar calE = Calendar.getInstance();
    colorNumber = $colorNumber;
    // cal.setTimeInMillis(current.getStart().getDateTime().getValue());
    // startDate = cal;
    if (current.getStart().getDate() != null) {
      String[] date = current.getStart().getDate().toString().split("-");
      calS.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
      date = current.getEnd().getDate().toString().split("-");
      calE.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
      startDate = calS;
      endDate = calE;
    } else {
      String date = current.getStart().getDateTime().toString();

      int dateCutoff = date.indexOf("T");
      int timeCutoff = date.indexOf("."); // to remove nanoseconds
      if (timeCutoff == -1) // if nanoseconds not set remove timezone shift
      timeCutoff = date.indexOf("-");
      if (timeCutoff == -1) // if timezone shift not set isolate time only
      timeCutoff = date.indexOf("Z");

      String time = date.substring(dateCutoff + 1, timeCutoff);
      String[] timeC = time.split(":");

      date = date.substring(0, dateCutoff);
      String[] dateC = date.split("-");

      calS.set(
          Integer.parseInt(dateC[0]),
          Integer.parseInt(dateC[1]) - 1,
          Integer.parseInt(dateC[2]),
          Integer.parseInt(timeC[0]),
          Integer.parseInt(timeC[1]),
          Integer.parseInt(timeC[2]));

      date = current.getEnd().getDateTime().toString();
      timeCutoff = date.indexOf(".");
      dateCutoff = date.indexOf("T");

      // to remove nanoseconds
      if (timeCutoff == -1) // if nanoseconds not set remove timezone shift
      timeCutoff = date.indexOf("-");
      if (timeCutoff == -1) // if timezone shift not set isolate time only
      timeCutoff = date.indexOf("Z");

      time = date.substring(dateCutoff + 1, timeCutoff);
      String[] timeE = time.split(":");

      date = date.substring(0, dateCutoff);
      dateC = date.split("-");
      calE.set(
          Integer.parseInt(dateC[0]),
          Integer.parseInt(dateC[1]) - 1,
          Integer.parseInt(dateC[2]),
          Integer.parseInt(timeE[0]),
          Integer.parseInt(timeE[1]),
          Integer.parseInt(timeE[2]));

      startDate = calS;
      endDate = calE;
    }

    id = current.getId();
    calendarName = current.getOrganizer().getDisplayName();
    // cal.setTimeInMillis(current.getEnd().getDateTime().getValue());
    // endDate = cal;
  }