Java Code Examples for com.google.api.services.calendar.model.Event#getStart()

The following examples show how to use com.google.api.services.calendar.model.Event#getStart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PreEvent(Snowflake _guildId, Event e) {
	guildId = _guildId;
	eventId = e.getId();

	color = EventColor.fromNameOrHexOrID(e.getColorId());

	recurrence = new Recurrence();

	if (e.getRecurrence() != null && e.getRecurrence().size() > 0) {
		recur = true;
		recurrence.fromRRule(e.getRecurrence().get(0));
	}

	if (e.getSummary() != null)
		summary = e.getSummary();

	if (e.getDescription() != null)
		description = e.getDescription();

	if (e.getLocation() != null)
		location = e.getLocation();


	startDateTime = e.getStart();
	endDateTime = e.getEnd();

	//Here is where I need to fix the display times
	GuildSettings settings = DatabaseManager.getManager().getSettings(guildId);
	//TODO: Support multiple calendars
	CalendarData data = DatabaseManager.getManager().getMainCalendar(guildId);

	Calendar cal = null;
	try {
		cal = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute();
	} catch (Exception ex) {
		Logger.getLogger().exception(null, "Failed to get proper date time for event!", ex, true, this.getClass());
	}

	if (cal != null) {

		//Check if either DateTime or just Date...
		if (e.getStart().getDateTime() != null) {
			//DateTime
			viewableStartDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDateTime().getValue(), cal.getTimeZone())));
			viewableEndDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDateTime().getValue(), cal.getTimeZone())));
		} else {
			//Just Date
			viewableStartDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDate().getValue(), cal.getTimeZone())));
			viewableEndDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDate().getValue(), cal.getTimeZone())));
		}
	} else {
		//Almost definitely not correct, but we need something displayed here.
		viewableStartDate = e.getStart();
		viewableEndDate = e.getEnd();
	}

	eventData = DatabaseManager.getManager().getEventData(guildId, e.getId());

	editing = false;
	lastEdit = System.currentTimeMillis();
}
 
Example 2
Source File: PreEvent.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PreEvent(Snowflake _guildId, Event e) {
	guildId = _guildId;
	eventId = e.getId();

	color = EventColor.fromNameOrHexOrID(e.getColorId());

	recurrence = new Recurrence();

	if (e.getRecurrence() != null && e.getRecurrence().size() > 0) {
		recur = true;
		recurrence.fromRRule(e.getRecurrence().get(0));
	}

	if (e.getSummary() != null)
		summary = e.getSummary();

	if (e.getDescription() != null)
		description = e.getDescription();

	if (e.getLocation() != null)
		location = e.getLocation();


	startDateTime = e.getStart();
	endDateTime = e.getEnd();

	//Here is where I need to fix the display times
	GuildSettings settings = DatabaseManager.getManager().getSettings(guildId);
	//TODO: Support multiple calendars
	CalendarData data = DatabaseManager.getManager().getMainCalendar(guildId);

	Calendar cal = null;
	try {
		cal = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute();
	} catch (Exception ex) {
		Logger.getLogger().exception(null, "Failed to get proper date time for event!", ex, true, this.getClass());
	}

	if (cal != null) {

		//Check if either DateTime or just Date...
		if (e.getStart().getDateTime() != null) {
			//DateTime
			viewableStartDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDateTime().getValue(), cal.getTimeZone())));
			viewableEndDate = new EventDateTime().setDateTime(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDateTime().getValue(), cal.getTimeZone())));
		} else {
			//Just Date
			viewableStartDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getStart().getDate().getValue(), cal.getTimeZone())));
			viewableEndDate = new EventDateTime().setDate(new DateTime(TimeUtils.applyTimeZoneOffset(e.getEnd().getDate().getValue(), cal.getTimeZone())));
		}
	} else {
		//Almost definitely not correct, but we need something displayed here.
		viewableStartDate = e.getStart();
		viewableEndDate = e.getEnd();
	}

	eventData = DatabaseManager.getManager().getEventData(guildId, e.getId());

	editing = false;
	lastEdit = System.currentTimeMillis();
}
 
Example 3
Source File: GCalEventDownloader.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates a set quartz-triggers for <code>job</code>. For each {@link When}
 * object of <code>event</code> a new trigger is created. That is the case
 * in recurring events where gcal creates one event (with one unique IcalUID)
 * and a set of {@link When}-object for each occurrence.
 *
 * @param job the {@link Job} to create triggers for
 * @param event the {@link CalendarEventEntry} to read the {@link When}-objects
 *            from
 * @param modifiedByEvent defines the name of an event which modifies the
 *            schedule of the new Trigger
 * @param isStartEvent indicator to identify whether this trigger will be
 *            triggering a start or an end command.
 *
 * @throws SchedulerException if there is an internal Scheduler error.
 */
protected boolean createTriggerAndSchedule(JobDetail job, Event event, String modifiedByEvent,
        boolean isStartEvent) {
    boolean triggersCreated = false;

    if (job == null) {
        logger.debug("job is null -> no triggers are created");
        return false;
    }

    String jobIdentity = event.getICalUID() + (isStartEvent ? "_start" : "_end");

    EventDateTime date = isStartEvent ? event.getStart() : event.getEnd();
    long dateValue = date.getDateTime().getValue();

    /*
     * TODO: TEE: do only create a new trigger when the start/endtime
     * lies in the future. This exclusion is necessary because the SimpleTrigger
     * triggers a job even if the startTime lies in the past. If somebody
     * knows the way to let quartz ignore such triggers this exclusion
     * can be omitted.
     */
    if (dateValue >= (new Date()).getTime()) {

        Trigger trigger;

        if (StringUtils.isBlank(modifiedByEvent)) {
            trigger = newTrigger().forJob(job)
                    .withIdentity(jobIdentity + "_" + dateValue + "_trigger", GCAL_SCHEDULER_GROUP)
                    .startAt(new Date(dateValue)).build();
        } else {
            trigger = newTrigger().forJob(job)
                    .withIdentity(jobIdentity + "_" + dateValue + "_trigger", GCAL_SCHEDULER_GROUP)
                    .startAt(new Date(dateValue)).modifiedByCalendar(modifiedByEvent).build();
        }

        try {
            scheduler.scheduleJob(job, trigger);
            triggersCreated = true;
        } catch (SchedulerException se) {
            logger.warn("scheduling Trigger '{}' throws an exception: {}", trigger, se);
        }
    }
    // }
    return triggersCreated;
}