function formatEvents(caldavEvents, gladysCalendar) {
  let events = [];

  caldavEvents.forEach((caldavEvent) => {
    if (caldavEvent.type !== 'VEVENT') {
      return;
    }

    if (typeof caldavEvent.rrule === 'undefined') {
      const newEvent = {
        external_id: caldavEvent.uid,
        selector: caldavEvent.uid,
        name: caldavEvent.summary,
        location: caldavEvent.location,
        description: caldavEvent.description,
        url: caldavEvent.href,
        calendar_id: gladysCalendar.id,
      };

      if (caldavEvent.start) {
        newEvent.start = this.dayjs
          .tz(this.dayjs(caldavEvent.start).format('YYYY-MM-DDTHH:mm:ss'), caldavEvent.start.tz)
          .format();
      }

      if (caldavEvent.end) {
        newEvent.end = this.dayjs
          .tz(this.dayjs(caldavEvent.end).format('YYYY-MM-DDTHH:mm:ss'), caldavEvent.end.tz)
          .format();
      } else if (caldavEvent.start && caldavEvent.duration) {
        newEvent.end = this.dayjs
          .tz(this.dayjs(caldavEvent.start).format('YYYY-MM-DDTHH:mm:ss'), caldavEvent.start.tz)
          .add(this.dayjs.duration(caldavEvent.duration))
          .format();
      }

      if (
        caldavEvent.start &&
        caldavEvent.start.tz === undefined &&
        (Number.isInteger(this.dayjs(caldavEvent.end).diff(this.dayjs(caldavEvent.start), 'days', true)) ||
          (!caldavEvent.end && !caldavEvent.duration))
      ) {
        newEvent.full_day = true;
      }

      if (newEvent.full_day && !caldavEvent.end) {
        newEvent.end = this.dayjs
          .tz(
            this.dayjs(caldavEvent.start)
              .add(1, 'day')
              .format('YYYY-MM-DDTHH:mm:ss'),
            caldavEvent.start.tz,
          )
          .format();
      }

      events.push(newEvent);
    } else {
      events = events.concat(this.formatRecurringEvents(caldavEvent, gladysCalendar).filter((e) => e !== null));
    }
  });

  return events;
}
@description Format events for Gladys calendar compatibility.
@param {Array} caldavEvents - Events to format.
@param {object} gladysCalendar - Gladys calendar where events are saved.
@returns {Array} All events formatted.
@example
formatEvents(caldavEvents, gladysCalendar)