fix off-by-day issue at syncing caldav events

This commit is contained in:
tibbi 2018-01-19 20:16:04 +01:00
parent a9ac3a955f
commit d5d56ec127
2 changed files with 17 additions and 2 deletions

View file

@ -17,6 +17,7 @@ import com.simplemobiletools.calendar.models.EventType
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 java.util.*
import kotlin.collections.ArrayList
@ -206,6 +207,7 @@ class CalDAVHandler(val context: Context) {
CalendarContract.Events.DESCRIPTION,
CalendarContract.Events.DTSTART,
CalendarContract.Events.DTEND,
CalendarContract.Events.EVENT_TIMEZONE,
CalendarContract.Events.DURATION,
CalendarContract.Events.ALL_DAY,
CalendarContract.Events.RRULE,
@ -222,8 +224,9 @@ class CalDAVHandler(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) / 1000).toInt()
var startTS = (cursor.getLongValue(CalendarContract.Events.DTSTART) / 1000).toInt()
var endTS = (cursor.getLongValue(CalendarContract.Events.DTEND) / 1000).toInt()
val timeZone = cursor.getStringValue(CalendarContract.Events.EVENT_TIMEZONE) ?: "UTC"
val allDay = cursor.getIntValue(CalendarContract.Events.ALL_DAY)
val rrule = cursor.getStringValue(CalendarContract.Events.RRULE) ?: ""
val location = cursor.getStringValue(CalendarContract.Events.EVENT_LOCATION) ?: ""
@ -231,6 +234,17 @@ class CalDAVHandler(val context: Context) {
val originalInstanceTime = cursor.getLongValue(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
val reminders = getCalDAVEventReminders(id)
if (allDay == 1 && timeZone == "UTC") {
val offset = DateTimeZone.getDefault().getOffset(System.currentTimeMillis()) / 1000
val FIVE_HOURS = 5 * 60 * 60
startTS -= offset
startTS += FIVE_HOURS
if (endTS != 0) {
endTS -= offset
endTS += FIVE_HOURS
}
}
if (endTS == 0) {
val duration = cursor.getStringValue(CalendarContract.Events.DURATION) ?: ""
endTS = startTS + Parser().parseDurationSeconds(duration)

View file

@ -53,8 +53,9 @@ class IcsImporter(val activity: SimpleActivity) {
inputStream.bufferedReader().use {
while (true) {
var line = it.readLine() ?: break
if (line.trim().isEmpty())
if (line.trim().isEmpty()) {
continue
}
if (line.substring(0, 1) == " ") {
line = prevLine + line.trim()