private static EventDateTime getEventDateTime(CalendarEventModel.CalendarEventTime dateTime) { if (dateTime == null) { return null; } EventDateTime eventDateTime = new EventDateTime(); // google's APIs want millisecond from epoch, and the timezone offset in minutes. if (dateTime.isDateOnly()) { eventDateTime.setDate(new DateTime(true, dateTime.getDateTime().toEpochSecond() * 1000, dateTime.getDateTime().getOffset().getTotalSeconds() / 60)); } else { eventDateTime.setDateTime(new DateTime( dateTime.getDateTime().toEpochSecond() * 1000, dateTime.getDateTime().getOffset().getTotalSeconds() / 60)); } return eventDateTime; }
private static CalendarEventModel.CalendarEventTime getEventTime(EventDateTime dateTime) { if (dateTime == null) { return null; } OffsetDateTime offsetDateTime; if (dateTime.getDate() == null) { offsetDateTime = OffsetDateTime.parse(dateTime.getDateTime().toString()); } else { offsetDateTime = OffsetDateTime.from( LocalDate.parse(dateTime.getDate().toString()).atStartOfDay(ZoneId.of("UTC"))); } return new CalendarEventModel.CalendarEventTime(offsetDateTime, dateTime.getDate() != null); }
private static Event newEvent() { Event event = new Event(); event.setSummary("New Event"); Date startDate = new Date(); Date endDate = new Date(startDate.getTime() + 3600000); DateTime start = new DateTime(startDate, TimeZone.getTimeZone("UTC")); event.setStart(new EventDateTime().setDateTime(start)); DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC")); event.setEnd(new EventDateTime().setDateTime(end)); return event; }
event.setDescription(body.getString("description")); EventDateTime start = new EventDateTime(); start.setDateTime(new DateTime(body.getLong("epochStart"))); event.setStart(start.setTimeZone(cal.getTimeZone())); EventDateTime end = new EventDateTime(); end.setDateTime(new DateTime(body.getLong("epochEnd"))); event.setEnd(end.setTimeZone(cal.getTimeZone())); ed.setEventEnd(event.getEnd().getDateTime().getValue());
if (e.getStart().getDateTime() != null) { 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 { 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())));
private static EventDateTime convertToEventDateTime(final org.joda.time.DateTime date, final boolean isAllDay, final DateTimeZone calendarTimeZone) { final EventDateTime result = new EventDateTime(); if (isAllDay) { result.setDate(convertToDate(date, calendarTimeZone.getOffset(date.getMillis()))); } else { result.setDateTime(convertToDateTime(date)); } result.setTimeZone(calendarTimeZone.getID()); return result; }
/** * Checks whether or not the start date is after the end date of the event. * * @param startRaw The date to check in format (yyyy/MM/dd-HH:mm:ss). * @param timezone The timezone of the calendar this event is for. * @param event The event that is currently being created. * @return <code>true</code> of the start is after the end, otherwise <code>false</code>. */ public static boolean startAfterEnd(String startRaw, TimeZone timezone, PreEvent event) { if (event.getEndDateTime() != null) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss"); sdf.setTimeZone(timezone); Date startDate = sdf.parse(startRaw); Date endDate = new Date(event.getEndDateTime().getDateTime().getValue()); return startDate.after(endDate); } catch (ParseException e) { return true; } } return false; }
event.setDescription(body.getString("description")); EventDateTime start = new EventDateTime(); start.setDateTime(new DateTime(body.getLong("epochStart"))); event.setStart(start.setTimeZone(cal.getTimeZone())); EventDateTime end = new EventDateTime(); end.setDateTime(new DateTime(body.getLong("epochEnd"))); event.setEnd(end.setTimeZone(cal.getTimeZone())); ed.setImageLink(body.getString("image")); ed.setEventId(eventId); ed.setEventEnd(event.getEnd().getDateTime().getValue());
/** * Checks whether or not the end date is before the start date of the event. * * @param endRaw The date to check in format (yyyy/MM/dd-HH:mm:ss). * @param timezone The timezone of the calendar this event is for. * @param event The event that is currently being created. * @return <code>true</code> if the end is before the start, otherwise <code>false</code>. */ public static boolean endBeforeStart(String endRaw, TimeZone timezone, PreEvent event) { if (event.getStartDateTime() != null) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss"); sdf.setTimeZone(timezone); Date endDate = sdf.parse(endRaw); Date startDate = new Date(event.getStartDateTime().getDateTime().getValue()); return endDate.before(startDate); } catch (ParseException e) { return true; } } return false; }
event.setDescription(body.getString("description")); EventDateTime start = new EventDateTime(); start.setDateTime(new DateTime(body.getLong("epochStart"))); event.setStart(start.setTimeZone(cal.getTimeZone())); EventDateTime end = new EventDateTime(); end.setDateTime(new DateTime(body.getLong("epochEnd"))); event.setEnd(end.setTimeZone(cal.getTimeZone())); ed.setImageLink(body.getString("image")); ed.setEventId(eventId); ed.setEventEnd(event.getEnd().getDateTime().getValue());
Date startMidDate = dateFormat.parse(composedTime); DateTime start = new DateTime(startMidDate); event.setStart(new EventDateTime().setDateTime(start)); } else { composedTime = startDate; DateTime startDateTime = new DateTime(composedTime); EventDateTime startEventDateTime = new EventDateTime().setDate(startDateTime); event.setStart(startEventDateTime); Date endMidDate = dateFormat.parse(composedTime); DateTime end = new DateTime(endMidDate); event.setEnd(new EventDateTime().setDateTime(end)); } else { composedTime = endDate; DateTime endDateTime = new DateTime(composedTime); EventDateTime endEventDateTime = new EventDateTime().setDate(endDateTime); event.setEnd(endEventDateTime);
private static org.joda.time.DateTime convertToJodaDateTime(final EventDateTime googleTime) { if (googleTime == null) { return null; } final org.joda.time.DateTime result; if (googleTime.getDateTime() == null) { result = convertToJodaDateTime(googleTime.getDate()); } else { result = convertToJodaDateTime(googleTime.getDateTime()); } return result; }
JSONObject jo = new JSONObject(); jo.put("id", e.getId()); jo.put("epochStart", e.getStart().getDateTime().getValue()); jo.put("epochEnd", e.getEnd().getDateTime().getValue());
event.setDescription(body.getString("description")); EventDateTime start = new EventDateTime(); start.setDateTime(new DateTime(body.getLong("epochStart"))); event.setStart(start.setTimeZone(cal.getTimeZone())); EventDateTime end = new EventDateTime(); end.setDateTime(new DateTime(body.getLong("epochEnd"))); event.setEnd(end.setTimeZone(cal.getTimeZone())); ed.setImageLink(body.getString("image")); ed.setEventId(eventId); ed.setEventEnd(event.getEnd().getDateTime().getValue());
Date startMidDate = dateFormat.parse(composedTime); DateTime start = new DateTime(startMidDate); event.setStart(new EventDateTime().setDateTime(start)); } else { composedTime = startDate; DateTime startDateTime = new DateTime(composedTime); EventDateTime startEventDateTime = new EventDateTime().setDate(startDateTime); event.setStart(startEventDateTime); Date endMidDate = dateFormat.parse(composedTime); DateTime end = new DateTime(endMidDate); event.setEnd(new EventDateTime().setDateTime(end)); } else { composedTime = endDate; DateTime endDateTime = new DateTime(composedTime); EventDateTime endEventDateTime = new EventDateTime().setDate(endDateTime); event.setEnd(endEventDateTime);
private static boolean inPast(Event event) { if (event.getStart().getDateTime() != null) return event.getStart().getDateTime().getValue() <= System.currentTimeMillis(); else return event.getStart().getDate().getValue() <= System.currentTimeMillis(); }
JSONObject jo = new JSONObject(); jo.put("id", e.getId()); jo.put("epochStart", e.getStart().getDateTime().getValue()); jo.put("epochEnd", e.getEnd().getDateTime().getValue());
event.setDescription(body.getString("description")); EventDateTime start = new EventDateTime(); start.setDateTime(new DateTime(body.getLong("epochStart"))); event.setStart(start.setTimeZone(cal.getTimeZone())); EventDateTime end = new EventDateTime(); end.setDateTime(new DateTime(body.getLong("epochEnd"))); event.setEnd(end.setTimeZone(cal.getTimeZone())); ed.setEventEnd(event.getEnd().getDateTime().getValue());
private static void fillEvent(Absence absence, Event event) { event.setSummary(absence.getEventSubject()); EventAttendee eventAttendee = new EventAttendee(); eventAttendee.setEmail(absence.getPerson().getEmail()); eventAttendee.setDisplayName(absence.getPerson().getNiceName()); event.setAttendees(Collections.singletonList(eventAttendee)); EventDateTime startEventDateTime; EventDateTime endEventDateTime; if (absence.isAllDay()) { // To create an all-day event, you must use setDate() having created DateTime objects using a String DateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN_YYYY_MM_DD); String startDateStr = dateFormat.format(absence.getStartDate()); String endDateStr = dateFormat.format(absence.getEndDate()); DateTime startDateTime = new DateTime(startDateStr); DateTime endDateTime = new DateTime(endDateStr); startEventDateTime = new EventDateTime().setDate(startDateTime); endEventDateTime = new EventDateTime().setDate(endDateTime); } else { DateTime dateTimeStart = new DateTime(absence.getStartDate()); DateTime dateTimeEnd = new DateTime(absence.getEndDate()); startEventDateTime = new EventDateTime().setDateTime(dateTimeStart); endEventDateTime = new EventDateTime().setDateTime(dateTimeEnd); } event.setStart(startEventDateTime); event.setEnd(endEventDateTime); }
if (event.getStart().getDateTime() != null) { model.setStartDate(dateFormat.format(new Date(event.getStart().getDateTime().getValue()))); model.setStartTime(timeFormat.format(new Date(event.getStart().getDateTime().getValue()))); } else { model.setStartDate(dateFormat.format(new Date(event.getStart().getDate().getValue()))); if (event.getEnd().getDateTime() != null) { model.setEndDate(dateFormat.format(new Date(event.getEnd().getDateTime().getValue()))); model.setEndTime(timeFormat.format(new Date(event.getEnd().getDateTime().getValue()))); } else { model.setEndDate(dateFormat.format(new Date(event.getEnd().getDate().getValue())));