From 3b0cec263f751181094bbba97ce0261d6fc05ff9 Mon Sep 17 00:00:00 2001 From: Naveen Date: Fri, 16 Jun 2023 03:02:01 +0530 Subject: [PATCH] Properly handle converting all-day recurring events to normal events --- .../calendar/pro/helpers/CalDAVHelper.kt | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt index 494ce7781..37dd4eb42 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt @@ -435,6 +435,25 @@ class CalDAVHelper(val context: Context) { put(Events.RRULE, repeatRule) } + val parentEventId = event.parentId + if (parentEventId != 0L) { + val parentEvent = context.eventsDB.getEventWithId(parentEventId) ?: return@apply + val isParentAllDay = parentEvent.getIsAllDay() + // original instance time must be in UTC when the parent is an all-day event + val originalInstanceTS = if (isParentAllDay && !event.getIsAllDay()) { + Formatter.getShiftedUtcTS(event.startTS) + } else { + event.startTS + } + put(Events.ORIGINAL_ID, parentEvent.getCalDAVEventId()) + put(Events.ORIGINAL_INSTANCE_TIME, originalInstanceTS * 1000L) + if (isParentAllDay) { + put(Events.ORIGINAL_ALL_DAY, 1) + } else { + put(Events.ORIGINAL_ALL_DAY, 0) + } + } + if (event.getIsAllDay()) { event.toUtcAllDayEvent() put(Events.ALL_DAY, 1) @@ -442,18 +461,6 @@ class CalDAVHelper(val context: Context) { put(Events.ALL_DAY, 0) } - val parentEventId = event.parentId - if (parentEventId != 0L) { - val parentEvent = context.eventsDB.getEventWithId(parentEventId) ?: return@apply - put(Events.ORIGINAL_ID, parentEvent.getCalDAVEventId()) - put(Events.ORIGINAL_INSTANCE_TIME, event.startTS * 1000L) - if (parentEvent.getIsAllDay()) { - put(Events.ORIGINAL_ALL_DAY, 1) - } else { - put(Events.ORIGINAL_ALL_DAY, 0) - } - } - put(Events.DTSTART, event.startTS * 1000L) put(Events.EVENT_TIMEZONE, event.getTimeZoneString()) if (event.repeatInterval > 0) {