Beispiel #1
0
  public Event newEvent(DateTime start, DateTime end, String title) {
    Event event = new Event();
    event.setSummary(title);
    Date startDate = new Date();
    Date endDate = new Date(startDate.getTime() + 3600000);

    event.setStart(new EventDateTime().setDateTime(start));
    event.setEnd(new EventDateTime().setDateTime(end));
    return event;
  }
  private Event createEvent(
      String roomName,
      String yearNum,
      String monthNum,
      String dayNum,
      String eventTime,
      String firmanavn,
      String attendeeEmail,
      String besrkivelse) {
    Event event = null;

    Calendar startCal = null;
    Calendar endCal = null;

    try {
      int year = Integer.parseInt(yearNum);
      int month = Integer.parseInt(monthNum) - 1;
      int day = Integer.parseInt(dayNum);

      startCal = Calendar.getInstance();
      startCal.set(Calendar.YEAR, year);
      startCal.set(Calendar.MONTH, month);
      startCal.set(Calendar.DATE, day);

      endCal = Calendar.getInstance();
      endCal.set(Calendar.YEAR, year);
      endCal.set(Calendar.MONTH, month);
      endCal.set(Calendar.DATE, day);

      if (eventTime.equals("early")) {
        startCal.set(Calendar.HOUR_OF_DAY, 8);
        endCal.set(Calendar.HOUR_OF_DAY, 12);
      } else if (eventTime.equals("late")) {
        startCal.set(Calendar.HOUR_OF_DAY, 13);
        endCal.set(Calendar.HOUR_OF_DAY, 17);
      } else if (eventTime.equals("full")) {
        startCal.set(Calendar.HOUR_OF_DAY, 8);
        endCal.set(Calendar.HOUR_OF_DAY, 17);
      } else if (eventTime.equals("community")) {
        startCal.set(Calendar.HOUR_OF_DAY, 17);
        startCal.set(Calendar.MINUTE, 1);
        endCal.set(Calendar.HOUR_OF_DAY, 22);
      } else {
        int startHour = Integer.parseInt(eventTime);
        startCal.set(Calendar.HOUR_OF_DAY, startHour);
        endCal.set(Calendar.HOUR_OF_DAY, (startHour + 1));
      }

      startCal.set(Calendar.MINUTE, 0);
      endCal.set(Calendar.MINUTE, 0);

      event = new Event();
      DateTime start = new DateTime(startCal.getTime(), TimeZone.getTimeZone("UTC"));
      event.setStart(new EventDateTime().setDateTime(start));
      DateTime end = new DateTime(endCal.getTime(), TimeZone.getTimeZone("UTC"));
      event.setEnd(new EventDateTime().setDateTime(end));

      event.setSummary(firmanavn);
      event.setLocation(roomName);
      event.setDescription(besrkivelse);

      EventAttendee room = new EventAttendee();
      room.setDisplayName(roomName);
      room.setEmail("*****@*****.**");

      List<EventAttendee> attendeeList = new ArrayList<>();
      attendeeList.add(room);

      EventAttendee attendee = new EventAttendee();
      attendee.setDisplayName(firmanavn);
      attendee.setEmail(attendeeEmail);
      attendeeList.add(attendee);

      event.setAttendees(attendeeList);

      GoogleCal googleCal = GoogleCal.getInstance();
      event = googleCal.addEvent(event);
    } catch (NumberFormatException nfe) {
      nfe.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return event;
  }