From 46e17aa697a4c92c319d465d7935492bd40e7f3e Mon Sep 17 00:00:00 2001 From: Naveen Date: Sat, 24 Jun 2023 15:35:23 +0530 Subject: [PATCH] Properly handle repeat limits Fixes these issues: - When choosing `Update/Delete this and all future occurrences`, the selected occurrence is never deleted/updated. - When choosing `Update this and all future occurrences`, the event is duplicated on the date of the selection --- .../calendar/pro/helpers/EventsHelper.kt | 14 +++++++++++--- .../calendar/pro/helpers/Parser.kt | 9 ++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt index 38f593d1e..d09fac49c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt @@ -225,9 +225,17 @@ class EventsHelper(val context: Context) { deleteEvents(eventIds, true) } - fun addEventRepeatLimit(eventId: Long, limitTS: Long) { - val time = Formatter.getDateTimeFromTS(limitTS) - eventsDB.updateEventRepetitionLimit(limitTS - time.hourOfDay, eventId) + fun addEventRepeatLimit(eventId: Long, occurrenceTS: Long) { + val event = eventsDB.getEventWithId(eventId) ?: return + val previousOccurrenceTS = occurrenceTS - event.repeatInterval // always update repeat limit of the occurrence preceding the one being edited + val repeatLimitDateTime = Formatter.getDateTimeFromTS(previousOccurrenceTS).withTimeAtStartOfDay() + val repeatLimitTS = if (event.getIsAllDay()) { + repeatLimitDateTime.seconds() + } else { + repeatLimitDateTime.withTime(23, 59, 59, 0).seconds() + } + + eventsDB.updateEventRepetitionLimit(repeatLimitTS, eventId) context.cancelNotification(eventId) context.cancelPendingIntent(eventId) if (config.caldavSync) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt index b0b317e39..a4c6f9436 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt @@ -145,7 +145,14 @@ class Parser { private fun getRepeatLimitString(event: Event) = when { event.repeatLimit == 0L -> "" event.repeatLimit < 0 -> ";$COUNT=${-event.repeatLimit}" - else -> ";$UNTIL=${Formatter.getDayCodeFromTS(event.repeatLimit)}" + else -> if (event.getIsAllDay()) { + ";$UNTIL=${Formatter.getDayCodeFromTS(event.repeatLimit)}" + } else { + val dateTime = Formatter.getUTCDateTimeFromTS(event.repeatLimit) + val dayCode = dateTime.toString(Formatter.DAYCODE_PATTERN) + val timeCode = dateTime.toString(Formatter.TIME_PATTERN) + ";$UNTIL=${dayCode}T${timeCode}Z" + } } private fun getByMonth(event: Event) = when {