fixing some CalDAV event repetition exception related issues
This commit is contained in:
parent
926807e942
commit
da4742e7b5
|
@ -17,6 +17,8 @@ import com.simplemobiletools.calendar.pro.objects.States.isUpdatingCalDAV
|
|||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALENDAR
|
||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR
|
||||
import org.joda.time.DateTimeZone
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
|
@ -195,8 +197,8 @@ class CalDAVHelper(val context: Context) {
|
|||
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
||||
val title = cursor.getStringValue(CalendarContract.Events.TITLE) ?: ""
|
||||
val description = cursor.getStringValue(CalendarContract.Events.DESCRIPTION) ?: ""
|
||||
val startTS = cursor.getLongValue(CalendarContract.Events.DTSTART) / 1000L
|
||||
var endTS = cursor.getLongValue(CalendarContract.Events.DTEND) / 1000L
|
||||
var startTS = cursor.getLongValue(CalendarContract.Events.DTSTART)
|
||||
var endTS = cursor.getLongValue(CalendarContract.Events.DTEND)
|
||||
val allDay = cursor.getIntValue(CalendarContract.Events.ALL_DAY)
|
||||
val rrule = cursor.getStringValue(CalendarContract.Events.RRULE) ?: ""
|
||||
val location = cursor.getStringValue(CalendarContract.Events.EVENT_LOCATION) ?: ""
|
||||
|
@ -204,6 +206,14 @@ class CalDAVHelper(val context: Context) {
|
|||
val originalInstanceTime = cursor.getLongValue(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
|
||||
val reminders = getCalDAVEventReminders(id)
|
||||
|
||||
if (startTS.toString().length == 13) {
|
||||
startTS /= 1000L
|
||||
}
|
||||
|
||||
if (endTS.toString().length == 13) {
|
||||
endTS /= 1000L
|
||||
}
|
||||
|
||||
if (endTS == 0L) {
|
||||
val duration = cursor.getStringValue(CalendarContract.Events.DURATION) ?: ""
|
||||
endTS = startTS + Parser().parseDurationSeconds(duration)
|
||||
|
@ -237,6 +247,7 @@ class CalDAVHelper(val context: Context) {
|
|||
eventsHelper.insertEvent(parentEvent, false, false)
|
||||
|
||||
event.parentId = parentEvent.id!!
|
||||
event.addRepetitionException(originalDayCode)
|
||||
eventsHelper.insertEvent(event, false, false)
|
||||
continue
|
||||
}
|
||||
|
@ -247,7 +258,16 @@ class CalDAVHelper(val context: Context) {
|
|||
if (exdate.length > 8) {
|
||||
val dates = exdate.split(",")
|
||||
dates.forEach {
|
||||
event.repetitionExceptions.add(it.substring(0, 8))
|
||||
if (it.endsWith("Z")) {
|
||||
// convert for example "20190216T230000Z" to "20190217000000" in Slovakia in a weird way
|
||||
val formatter = DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss'Z'")
|
||||
val offset = DateTimeZone.getDefault().getOffset(System.currentTimeMillis())
|
||||
val dt = formatter.parseDateTime(it).plusMillis(offset)
|
||||
val daycode = Formatter.getDayCodeFromDateTime(dt)
|
||||
event.repetitionExceptions.add(daycode)
|
||||
} else {
|
||||
event.repetitionExceptions.add(it.substring(0, 8))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue