Skip to content

2748 #2750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2025
Merged

2748 #2750

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_OUTPUT_PROPERTY;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.createCustomEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.getCalendarTimezone;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.getEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.updateEvent;

Expand All @@ -35,6 +36,8 @@
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils.CustomEvent;
import com.bytechef.google.commons.GoogleServices;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.EventAttendee;
import java.io.IOException;
Expand Down Expand Up @@ -73,7 +76,9 @@ private GoogleCalendarAddAttendeesToEventAction() {
public static CustomEvent perform(Parameters inputParameters, Parameters connectionParameters, Context context)
throws IOException {

Event event = getEvent(inputParameters, connectionParameters);
Calendar calendar = GoogleServices.getCalendar(connectionParameters);

Event event = getEvent(inputParameters, calendar);

List<String> newAttendees = inputParameters.getList(ATTENDEES, String.class, List.of());

Expand All @@ -91,6 +96,8 @@ public static CustomEvent perform(Parameters inputParameters, Parameters connect
.addAll(newEventAttendees);
}

return createCustomEvent(updateEvent(inputParameters, connectionParameters, event));
String timezone = getCalendarTimezone(calendar);

return createCustomEvent(updateEvent(inputParameters, connectionParameters, event), timezone);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.FileEntry;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils.CustomEvent;
import com.bytechef.google.commons.GoogleServices;
import com.google.api.services.calendar.Calendar;
Expand Down Expand Up @@ -193,11 +194,14 @@ public static CustomEvent perform(Parameters inputParameters, Parameters connect
.map(attendee -> new EventAttendee().setEmail(attendee))
.toList();

Calendar calendar = GoogleServices.getCalendar(connectionParameters);
String timezone = GoogleCalendarUtils.getCalendarTimezone(calendar);

Event event = new Event()
.setAttachments(eventAttachments)
.setAttendees(eventAttendees)
.setDescription(inputParameters.getString(DESCRIPTION))
.setEnd(createEventDateTime(inputParameters, END))
.setEnd(createEventDateTime(inputParameters, END, timezone))
.setGuestsCanInviteOthers(inputParameters.getBoolean(GUEST_CAN_INVITE_OTHERS))
.setGuestsCanModify(inputParameters.getBoolean(GUEST_CAN_MODIFY))
.setGuestsCanSeeOtherGuests(inputParameters.getBoolean(GUEST_CAN_SEE_OTHER_GUESTS))
Expand All @@ -206,16 +210,14 @@ public static CustomEvent perform(Parameters inputParameters, Parameters connect
new Event.Reminders()
.setUseDefault(inputParameters.getRequiredBoolean(USE_DEFAULT))
.setOverrides(inputParameters.getList(REMINDERS, EventReminder.class, List.of())))
.setStart(createEventDateTime(inputParameters, START))
.setStart(createEventDateTime(inputParameters, START, timezone))
.setSummary(inputParameters.getString(SUMMARY));

Calendar calendar = GoogleServices.getCalendar(connectionParameters);

Event newEvent = calendar.events()
.insert(inputParameters.getRequiredString(CALENDAR_ID), event)
.setSendUpdates(inputParameters.getString(SEND_UPDATES))
.execute();

return createCustomEvent(newEvent);
return createCustomEvent(newEvent, timezone);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.SEND_UPDATES_PROPERTY;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.TEXT;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.createCustomEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.getCalendarTimezone;

import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.Context;
Expand Down Expand Up @@ -67,6 +68,6 @@ public static CustomEvent perform(Parameters inputParameters, Parameters connect
.setSendUpdates(inputParameters.getString(SEND_UPDATES))
.execute();

return createCustomEvent(event);
return createCustomEvent(event, getCalendarTimezone(calendar));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.SUMMARY;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.createCustomEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.createEventDateTime;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.getCalendarTimezone;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.getEvent;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.updateEvent;

Expand All @@ -44,6 +45,8 @@
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils;
import com.bytechef.component.google.calendar.util.GoogleCalendarUtils.CustomEvent;
import com.bytechef.google.commons.GoogleServices;
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.EventAttendee;
import java.io.IOException;
Expand Down Expand Up @@ -117,7 +120,8 @@ private GoogleCalendarUpdateEventAction() {
public static CustomEvent perform(Parameters inputParameters, Parameters connectionParameters, Context context)
throws IOException {

Event event = getEvent(inputParameters, connectionParameters);
Calendar calendar = GoogleServices.getCalendar(connectionParameters);
Event event = getEvent(inputParameters, calendar);

List<String> attendees = inputParameters.getList(ATTENDEES, String.class, List.of());

Expand Down Expand Up @@ -148,12 +152,14 @@ public static CustomEvent perform(Parameters inputParameters, Parameters connect
event.setSummary(summary);
}

String calendarTimezone = getCalendarTimezone(calendar);

if (inputParameters.getBoolean(ALL_DAY) != null) {
event
.setEnd(createEventDateTime(inputParameters, END))
.setStart(createEventDateTime(inputParameters, START));
.setEnd(createEventDateTime(inputParameters, END, calendarTimezone))
.setStart(createEventDateTime(inputParameters, START, calendarTimezone));
}

return createCustomEvent(updateEvent(inputParameters, connectionParameters, event));
return createCustomEvent(updateEvent(inputParameters, connectionParameters, event), calendarTimezone);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_OUTPUT_PROPERTY;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.RESOURCE_ID;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.convertToDateViaSqlTimestamp;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.convertLocalDateTimeToDateInTimezone;
import static com.bytechef.component.google.calendar.util.GoogleCalendarUtils.createCustomEvent;

import com.bytechef.component.definition.OptionsDataSource.TriggerOptionsFunction;
Expand Down Expand Up @@ -137,18 +137,20 @@ protected static CustomEvent webhookRequest(

Calendar calendar = GoogleServices.getCalendar(connectionParameters);

String calendarTimezone = GoogleCalendarUtils.getCalendarTimezone(calendar);

List<Event> events = calendar.events()
.list(inputParameters.getRequiredString(CALENDAR_ID))
.setOrderBy("updated")
.setShowDeleted(true)
.setUpdatedMin(new DateTime(convertToDateViaSqlTimestamp(currentRowNum)))
.setUpdatedMin(new DateTime(convertLocalDateTimeToDateInTimezone(currentRowNum, calendarTimezone)))
.execute()
.getItems();

context.data(data -> data.put(WORKFLOW, "lastTimeChecked", now));

if (events != null && !events.isEmpty()) {
return createCustomEvent(events.getLast());
return createCustomEvent(events.getLast(), calendarTimezone);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.ALL_DAY;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.CALENDAR_ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.DATE_RANGE;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.END;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_ID;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.EVENT_TYPE;
import static com.bytechef.component.google.calendar.constant.GoogleCalendarConstants.FROM;
Expand Down Expand Up @@ -47,6 +48,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.ArrayList;
Expand All @@ -62,16 +64,23 @@ public class GoogleCalendarUtils {
private GoogleCalendarUtils() {
}

public static Date convertToDateViaSqlTimestamp(LocalDateTime dateToConvert) {
return dateToConvert == null ? null : java.sql.Timestamp.valueOf(dateToConvert);
public static Date convertLocalDateTimeToDateInTimezone(LocalDateTime dateToConvert, String timezone) {
if (dateToConvert == null) {
return null;
} else {
ZoneId zoneId = ZoneId.of(timezone);
ZonedDateTime zonedDateTime = dateToConvert.atZone(zoneId);

return Date.from(zonedDateTime.toInstant());
}
}

public static Temporal convertToTemporalFromEventDateTime(EventDateTime eventDateTime) {
public static Temporal convertToTemporalFromEventDateTime(EventDateTime eventDateTime, String timezone) {
if (eventDateTime != null) {
DateTime dateTime = eventDateTime.getDateTime();

if (dateTime != null) {
return LocalDateTime.ofInstant(Instant.parse(dateTime.toString()), ZoneId.systemDefault());
return LocalDateTime.ofInstant(Instant.parse(dateTime.toString()), ZoneId.of(timezone));
}

DateTime allDayDate = eventDateTime.getDate();
Expand All @@ -82,27 +91,37 @@ public static Temporal convertToTemporalFromEventDateTime(EventDateTime eventDat
}
}

public static EventDateTime createEventDateTime(Parameters inputParameters, String time) {
public static EventDateTime createEventDateTime(Parameters inputParameters, String time, String timezone) {
EventDateTime eventDateTime = new EventDateTime();

if (inputParameters.getRequiredBoolean(ALL_DAY)) {
Date date = inputParameters.getRequiredDate(time);

if (time.equals(END)) {
java.util.Calendar javaCalendar = java.util.Calendar.getInstance();
javaCalendar.setTime(date);
javaCalendar.add(java.util.Calendar.DAY_OF_MONTH, 1);

date = javaCalendar.getTime();
}

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

eventDateTime.setDate(new DateTime(simpleDateFormat.format(date)));
} else {
eventDateTime.setDateTime(
new DateTime(convertToDateViaSqlTimestamp(inputParameters.getRequiredLocalDateTime(time))));
new DateTime(
convertLocalDateTimeToDateInTimezone(inputParameters.getRequiredLocalDateTime(time), timezone)));
}

return eventDateTime;
}

public static CustomEvent createCustomEvent(Event event) {
public static CustomEvent createCustomEvent(Event event, String timezone) {
return new CustomEvent(
event.getICalUID(), event.getId(), event.getSummary(), event.getDescription(),
convertToTemporalFromEventDateTime(event.getStart()), convertToTemporalFromEventDateTime(event.getEnd()),
convertToTemporalFromEventDateTime(event.getStart(), timezone),
convertToTemporalFromEventDateTime(event.getEnd(), timezone),
event.getEtag(), event.getEventType(), event.getHtmlLink(), event.getStatus(), event.getLocation(),
event.getHangoutLink(), event.getAttendees(), event.getAttachments(), event.getReminders());
}
Expand Down Expand Up @@ -141,54 +160,56 @@ public static List<CustomEvent> getCustomEvents(Parameters inputParameters, Para
.execute()
.getItems();

String calendarTimezone = getCalendarTimezone(calendar);

Map<String, LocalDateTime> timePeriod = inputParameters.getMap(DATE_RANGE, LocalDateTime.class, Map.of());

LocalDateTime from = timePeriod.get(FROM);
LocalDateTime to = timePeriod.get(TO);

return convertToCustomEvents(filterEvents(from, to, items));
return convertToCustomEvents(filterEvents(from, to, items, calendarTimezone), calendarTimezone);
}

private static List<Event> filterEvents(LocalDateTime from, LocalDateTime to, List<Event> items) {
private static List<Event> filterEvents(LocalDateTime from, LocalDateTime to, List<Event> items, String timezone) {
if (from == null && to == null) {
return items;
} else if (from != null && to == null) {

return items.stream()
.filter(event -> isAfter(event.getEnd(), from))
.filter(event -> isAfter(event.getEnd(), from, timezone))
.toList();

} else if (from == null) {

return items.stream()
.filter(event -> isBefore(event.getStart(), to))
.filter(event -> isBefore(event.getStart(), to, timezone))
.toList();
} else {
return items.stream()
.filter(event -> isWithinRange(event, from, to))
.filter(event -> isWithinRange(event, from, to, timezone))
.toList();
}
}

private static boolean isAfter(EventDateTime eventDateTime, LocalDateTime from) {
Temporal temporal = convertToTemporalFromEventDateTime(eventDateTime);
private static boolean isAfter(EventDateTime eventDateTime, LocalDateTime from, String timezone) {
Temporal temporal = convertToTemporalFromEventDateTime(eventDateTime, timezone);

return temporal instanceof LocalDateTime localDateTime ? localDateTime.isAfter(from)
: LocalDateTime.of(((LocalDate) temporal).minusDays(1), LOCAL_TIME_MAX)
.isAfter(from);
}

private static boolean isBefore(EventDateTime eventDateTime, LocalDateTime to) {
Temporal temporal = convertToTemporalFromEventDateTime(eventDateTime);
private static boolean isBefore(EventDateTime eventDateTime, LocalDateTime to, String timezone) {
Temporal temporal = convertToTemporalFromEventDateTime(eventDateTime, timezone);

return temporal instanceof LocalDateTime localDateTime ? localDateTime.isBefore(to)
: LocalDateTime.of((LocalDate) temporal, LOCAL_TIME_MIN)
.isBefore(to);
}

private static boolean isWithinRange(Event event, LocalDateTime from, LocalDateTime to) {
Temporal start = convertToTemporalFromEventDateTime(event.getStart());
Temporal end = convertToTemporalFromEventDateTime(event.getEnd());
private static boolean isWithinRange(Event event, LocalDateTime from, LocalDateTime to, String timezone) {
Temporal start = convertToTemporalFromEventDateTime(event.getStart(), timezone);
Temporal end = convertToTemporalFromEventDateTime(event.getEnd(), timezone);

if (start instanceof LocalDateTime startLDT && end instanceof LocalDateTime endLDT) {

Expand All @@ -208,15 +229,13 @@ private static boolean isWithinRange(Event event, LocalDateTime from, LocalDateT
return false;
}

private static List<CustomEvent> convertToCustomEvents(List<Event> eventList) {
private static List<CustomEvent> convertToCustomEvents(List<Event> eventList, String timezone) {
return eventList.stream()
.map(GoogleCalendarUtils::createCustomEvent)
.map(event -> createCustomEvent(event, timezone))
.toList();
}

public static Event getEvent(Parameters inputParameters, Parameters connectionParameters) throws IOException {
Calendar calendar = GoogleServices.getCalendar(connectionParameters);

public static Event getEvent(Parameters inputParameters, Calendar calendar) throws IOException {
return calendar
.events()
.get(inputParameters.getRequiredString(CALENDAR_ID), inputParameters.getRequiredString(EVENT_ID))
Expand Down Expand Up @@ -257,6 +276,20 @@ public static Event updateEvent(Parameters inputParameters, Parameters connectio
.execute();
}

public static String getCalendarTimezone(Calendar calendar) throws IOException {
return calendar
.settings()
.list()
.execute()
.getItems()
.stream()
.filter(setting -> setting.getId()
.equals("timezone"))
.findFirst()
.get()
.getValue();
}

@SuppressFBWarnings("EI")
public record CustomEvent(
String iCalUID, String id, String summary, String description, Temporal startTime, Temporal endTime,
Expand Down
Loading